3035fa5f2b90ee725150a549b5f593d28252774a
[platform/upstream/syncevolution.git] / src / dbus / server / pim / full-view.h
1 /*
2  * Copyright (C) 2012 Intel Corporation
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) version 3.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301  USA
18  */
19
20 #ifndef INCL_SYNCEVO_DBUS_SERVER_FULL_VIEW
21 #define INCL_SYNCEVO_DBUS_SERVER_FULL_VIEW
22
23 #include "view.h"
24
25 #include <syncevo/declarations.h>
26 SE_BEGIN_CXX
27
28 /**
29  * The view which takes input directly from IndividualAggregator
30  * and maintains a sorted set of contacts as result.
31  */
32 class FullView : public IndividualView
33 {
34     FolksIndividualAggregatorCXX m_folks;
35     boost::shared_ptr<LocaleFactory> m_locale;
36     bool m_isQuiescent;
37     boost::weak_ptr<FullView> m_self;
38     Timeout m_waitForIdle;
39     std::set<FolksIndividualCXX> m_pendingModifications;
40     Timeout m_quiescenceDelay;
41
42     /**
43      * Sorted vector. Sort order is maintained by this class.
44      */
45     typedef boost::ptr_vector<IndividualData> Entries_t;
46     Entries_t m_entries;
47
48     /**
49      * The sort object to be used.
50      */
51     boost::shared_ptr<IndividualCompare> m_compare;
52
53     FullView(const FolksIndividualAggregatorCXX &folks,
54              const boost::shared_ptr<LocaleFactory> &locale);
55     void init(const boost::shared_ptr<FullView> &self);
56
57     /**
58      * Run via m_waitForIdle if (and only if) something
59      * changed.
60      */
61     void onIdle();
62
63     /**
64      * Ensure that onIdle() gets invoked.
65      */
66     void waitForIdle();
67
68     /**
69      * Adds the new individual to m_entries, transfers ownership
70      * (data == NULL afterwards).
71      */
72     void doAddIndividual(Entries_t::auto_type &data);
73
74  public:
75     /**
76      * @param folks     the aggregator to use
77      */
78     static boost::shared_ptr<FullView> create(const FolksIndividualAggregatorCXX &folks,
79                                               const boost::shared_ptr<LocaleFactory> &locale);
80
81     /** FolksIndividualAggregator "individuals-changed" slot */
82     void individualsChanged(GeeSet *added,
83                             GeeSet *removed,
84                             gchar *message,
85                             FolksPersona *actor,
86                             FolksGroupDetailsChangeReason reason = FOLKS_GROUP_DETAILS_CHANGE_REASON_NONE);
87
88     /** GObject "notify" slot */
89     void individualModified(gpointer gobject,
90                             GParamSpec *pspec);
91
92     /**
93      * FolksIndividualAggregator "is-quiescent" property change slot.
94      *
95      * It turned out that "quiescence" is only set to true once in
96      * FolksIndividualAggregator. The code which watches that signal
97      * is still in place, but it will only get invoked once.
98      *
99      * Therefore the main mechanism for emitting m_quiescenceSignal in
100      * FullView is an idle callback which gets invoked each time the
101      * daemon has nothing to do, which implies that (at least for now)
102      * libfolks has no pending work to do.
103      */
104     void quiescenceChanged();
105
106     /**
107      * Mirrors the FolksIndividualAggregator "is-quiesent" state:
108      * false initially, then true for the rest of the run.
109      */
110     virtual bool isQuiescent() const { return m_isQuiescent; }
111
112     /**
113      * Add a FolksIndividual. Starts monitoring it for changes.
114      */
115     void addIndividual(FolksIndividual *individual);
116
117     /**
118      * Deal with FolksIndividual modification.
119      */
120     void modifyIndividual(FolksIndividual *individual);
121
122    /**
123      * Remove a FolksIndividual.
124      */
125     void removeIndividual(FolksIndividual *individual);
126
127     /**
128      * Set new sort method. Reorders current set of entries on the
129      * fly. Default is lexicographical comparison of the single-string
130      * full name.
131      *
132      * @param compare   the new ordering or NULL for the builtin default (last/first with ASCII lexicographic comparison)
133      */
134     void setCompare(const boost::shared_ptr<IndividualCompare> &compare);
135
136     // from IndividualView
137     virtual void doStart();
138     virtual int size() const { return (int)m_entries.size(); }
139     virtual const IndividualData *getContact(int index) { return (index >= 0 && (unsigned)index < m_entries.size()) ? &m_entries[index] : NULL; }
140 };
141
142 SE_END_CXX
143
144 #endif // INCL_SYNCEVO_DBUS_SERVER_PIM_FULL_VIEW