~elementary-pantheon/poa-eds-bridge/say-were-desktop

« back to all changes in this revision

Viewing changes to src/POAModule.vala

  • Committer: Corentin Noël
  • Date: 2015-12-26 21:12:39 UTC
  • Revision ID: corentin@elementary.io-20151226211239-w5i1zdz7n3k10nu1
Updated to the latest bindings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    }
10
10
 
11
11
    construct {
12
 
        get_extensible ().bus_acquired.connect (() => {on_bus_acquired ();});
 
12
        uoa_to_eds = new HashTable<uint, string> (null, null);
 
13
        ((E.DBusServer) get_extensible ()).bus_acquired.connect_after ((connection) => on_bus_acquired ());
13
14
    }
14
15
 
15
16
    public bool get_access_token_sync (E.Source source, GLib.Cancellable? cancellable, out string? access_token, out int expires_in) throws GLib.Error {
131
132
 
132
133
    private void on_bus_acquired () {
133
134
        manager = new Ag.Manager ();
134
 
        uoa_to_eds = new HashTable<uint, string> (null, null);
135
135
        services_from_source = new HashTable<string, HashTable<string, Ag.AccountService>> (str_hash, str_equal);
136
 
        populate_accounts_table (manager.list ());
137
 
        foreach (var account_id in manager.list ()) {
 
136
        populate_accounts_table ();
 
137
        manager.list ().foreach ((account_id) => {
138
138
            on_account_created (account_id);
139
 
        }
 
139
        });
140
140
 
141
141
        manager.account_created.connect ((id) => {on_account_created (id);});
142
142
        manager.account_deleted.connect ((id) => {on_account_deleted (id);});
150
150
        }
151
151
    }
152
152
 
153
 
    private void populate_accounts_table (List<uint> accounts_ids) {
 
153
    private void populate_accounts_table () {
154
154
        var trash = new Queue<E.Source> ();
155
 
        foreach (var source in ((E.SourceRegistryServer)get_extensible ()).list_sources (E.SOURCE_EXTENSION_UOA)) {
 
155
        var extensible = get_extensible ();
 
156
        ((E.SourceRegistryServer) extensible).list_sources (E.SOURCE_EXTENSION_UOA).foreach ((source) => {
156
157
            var uoa_ext = (E.SourceUoa)source.get_extension (E.SOURCE_EXTENSION_UOA);
157
158
            var account_id = uoa_ext.get_account_id ();
158
159
            if (account_id == 0)
159
 
                continue;
 
160
                return;
160
161
 
161
162
            var exists = uoa_to_eds.get (account_id);
162
163
            if (exists != null)
163
 
                continue;
 
164
                return;
164
165
 
165
166
            /* Verify the POA account still exists. */
166
 
            var match = accounts_ids.find (account_id).copy ();
 
167
            unowned GLib.List<uint> match = manager.list ().find (account_id);
167
168
            var account = manager.get_account (account_id);
168
169
            if (match != null && account != null) {
169
170
                uoa_to_eds.set (account_id, source.dup_uid ());
171
172
            } else {
172
173
                trash.push_tail (source);
173
174
            }
174
 
        }
 
175
        });
175
176
 
176
177
        while (trash.is_empty () == false) {
177
178
            var source = trash.pop_head ();
189
190
     */
190
191
    private HashTable<string, Ag.AccountService> new_account_services (Ag.Account account) {
191
192
        var account_services = new HashTable<string, Ag.AccountService> (str_hash, str_equal);
192
 
        foreach (var service in account.list_services ()) {
 
193
        account.list_services ().foreach ((service) => {
193
194
            account_services.set (service.get_service_type (), new Ag.AccountService (account, service));
194
 
        }
 
195
        });
195
196
 
196
197
        return account_services;
197
198
    }
198
199
 
199
200
    private void create_collection (Ag.Account account) {
200
201
        var collection_source = new_source ();
 
202
        return_if_fail (collection_source is E.Source);
 
203
 
201
204
        config_sources (collection_source, account);
202
 
        ((E.SourceRegistryServer)get_extensible ()).add_source (collection_source);
 
205
        ((E.SourceRegistryServer) get_extensible ()).add_source (collection_source);
203
206
        uoa_to_eds.set (account.id, collection_source.dup_uid ());
204
207
    }
205
208
 
209
212
    private void config_sources (E.Source collection_source, Ag.Account account) {
210
213
        var account_services = new_account_services (account);
211
214
 
212
 
        var source_extension = collection_source.get_extension (E.SOURCE_EXTENSION_AUTHENTICATION);
 
215
        unowned E.SourceExtension source_extension = collection_source.get_extension (E.SOURCE_EXTENSION_AUTHENTICATION);
213
216
        ((E.SourceAuthentication)source_extension).set_user (account.display_name);
214
217
        collection_source.set_display_name (manager.get_provider (account.get_provider_name ()).get_display_name ());
215
218
        account.bind_property ("enabled", collection_source, "enabled", BindingFlags.SYNC_CREATE);
218
221
        account.bind_property ("id", source_extension, "account-id", BindingFlags.SYNC_CREATE);
219
222
 
220
223
        source_extension = collection_source.get_extension (E.SOURCE_EXTENSION_COLLECTION);
221
 
        var source_collection = (E.SourceCollection)source_extension;
 
224
        unowned E.SourceCollection source_collection = (E.SourceCollection)source_extension;
222
225
        var user_identity = account.get_display_name ();
223
226
        if (user_identity != null) {
224
227
            source_collection.set_identity (user_identity);
236
239
                configure_separate_calendar (collection_source, account_service);
237
240
            }
238
241
 
239
 
            account_service.enabled.connect ((is_enabled) => {source_collection.calendar_enabled = is_enabled;});
240
 
            source_collection.calendar_enabled = account_service.get_enabled ();
241
 
 
 
242
            account_service.bind_property ("enabled", source_collection, "calendar-enabled", BindingFlags.SYNC_CREATE);
242
243
            supports_oauth2 |= POAUtils.check_oauth2_support (account_service);
243
244
        }
244
245
 
253
254
                configure_separate_email (collection_source, account_service);
254
255
            }
255
256
 
256
 
            account_service.enabled.connect ((is_enabled) => {source_collection.mail_enabled = is_enabled;});
257
 
            source_collection.mail_enabled = account_service.get_enabled ();
258
 
 
 
257
            account_service.bind_property ("enabled", source_collection, "mail-enabled", BindingFlags.SYNC_CREATE);
259
258
            supports_oauth2 |= POAUtils.check_oauth2_support (account_service);
260
259
        }
261
260
 
270
269
                configure_separate_contacts (collection_source, account_service);
271
270
            }
272
271
 
273
 
            account_service.enabled.connect ((is_enabled) => {source_collection.contacts_enabled = is_enabled;});
274
 
            source_collection.contacts_enabled = account_service.get_enabled ();
275
 
 
 
272
            account_service.bind_property ("enabled", source_collection, "contacts-enabled", BindingFlags.SYNC_CREATE);
276
273
            supports_oauth2 |= POAUtils.check_oauth2_support (account_service);
277
274
        }
278
275