summaryrefslogtreecommitdiff
path: root/src/dbus/server/pim/full-view.h
blob: 3035fa5f2b90ee725150a549b5f593d28252774a (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Copyright (C) 2012 Intel Corporation
 *
 * 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) version 3.
 *
 * 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 Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#ifndef INCL_SYNCEVO_DBUS_SERVER_FULL_VIEW
#define INCL_SYNCEVO_DBUS_SERVER_FULL_VIEW

#include "view.h"

#include <syncevo/declarations.h>
SE_BEGIN_CXX

/**
 * The view which takes input directly from IndividualAggregator
 * and maintains a sorted set of contacts as result.
 */
class FullView : public IndividualView
{
    FolksIndividualAggregatorCXX m_folks;
    boost::shared_ptr<LocaleFactory> m_locale;
    bool m_isQuiescent;
    boost::weak_ptr<FullView> m_self;
    Timeout m_waitForIdle;
    std::set<FolksIndividualCXX> m_pendingModifications;
    Timeout m_quiescenceDelay;

    /**
     * Sorted vector. Sort order is maintained by this class.
     */
    typedef boost::ptr_vector<IndividualData> Entries_t;
    Entries_t m_entries;

    /**
     * The sort object to be used.
     */
    boost::shared_ptr<IndividualCompare> m_compare;

    FullView(const FolksIndividualAggregatorCXX &folks,
             const boost::shared_ptr<LocaleFactory> &locale);
    void init(const boost::shared_ptr<FullView> &self);

    /**
     * Run via m_waitForIdle if (and only if) something
     * changed.
     */
    void onIdle();

    /**
     * Ensure that onIdle() gets invoked.
     */
    void waitForIdle();

    /**
     * Adds the new individual to m_entries, transfers ownership
     * (data == NULL afterwards).
     */
    void doAddIndividual(Entries_t::auto_type &data);

 public:
    /**
     * @param folks     the aggregator to use
     */
    static boost::shared_ptr<FullView> create(const FolksIndividualAggregatorCXX &folks,
                                              const boost::shared_ptr<LocaleFactory> &locale);

    /** FolksIndividualAggregator "individuals-changed" slot */
    void individualsChanged(GeeSet *added,
                            GeeSet *removed,
                            gchar *message,
                            FolksPersona *actor,
                            FolksGroupDetailsChangeReason reason = FOLKS_GROUP_DETAILS_CHANGE_REASON_NONE);

    /** GObject "notify" slot */
    void individualModified(gpointer gobject,
                            GParamSpec *pspec);

    /**
     * FolksIndividualAggregator "is-quiescent" property change slot.
     *
     * It turned out that "quiescence" is only set to true once in
     * FolksIndividualAggregator. The code which watches that signal
     * is still in place, but it will only get invoked once.
     *
     * Therefore the main mechanism for emitting m_quiescenceSignal in
     * FullView is an idle callback which gets invoked each time the
     * daemon has nothing to do, which implies that (at least for now)
     * libfolks has no pending work to do.
     */
    void quiescenceChanged();

    /**
     * Mirrors the FolksIndividualAggregator "is-quiesent" state:
     * false initially, then true for the rest of the run.
     */
    virtual bool isQuiescent() const { return m_isQuiescent; }

    /**
     * Add a FolksIndividual. Starts monitoring it for changes.
     */
    void addIndividual(FolksIndividual *individual);

    /**
     * Deal with FolksIndividual modification.
     */
    void modifyIndividual(FolksIndividual *individual);

   /**
     * Remove a FolksIndividual.
     */
    void removeIndividual(FolksIndividual *individual);

    /**
     * Set new sort method. Reorders current set of entries on the
     * fly. Default is lexicographical comparison of the single-string
     * full name.
     *
     * @param compare   the new ordering or NULL for the builtin default (last/first with ASCII lexicographic comparison)
     */
    void setCompare(const boost::shared_ptr<IndividualCompare> &compare);

    // from IndividualView
    virtual void doStart();
    virtual int size() const { return (int)m_entries.size(); }
    virtual const IndividualData *getContact(int index) { return (index >= 0 && (unsigned)index < m_entries.size()) ? &m_entries[index] : NULL; }
};

SE_END_CXX

#endif // INCL_SYNCEVO_DBUS_SERVER_PIM_FULL_VIEW