~ubuntu-branches/ubuntu/quantal/folks/quantal

« back to all changes in this revision

Viewing changes to backends/telepathy/lib/tpf-persona-store.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-09-12 09:48:10 UTC
  • mfrom: (1.6.2)
  • Revision ID: package-import@ubuntu.com-20120912094810-6zlx8889hcovxj7p
Tags: 0.7.4.1-0ubuntu1
* New upstream bugfix release
* debian/control:
  - Bump build-depends on libglib2.0-dev, valac-0.18, libvala-0.18-dev
* debian/libfolks-eds25.symbols:
* debian/libfolks25.symbols:
  - Updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
   * this should *not* be cleared in _reset(). */
63
63
  private HashMap<string, File> _avatars = new HashMap<string, File> ();
64
64
 
65
 
  private Connection _conn;
 
65
  private Connection? _conn; /* null when disconnected */
66
66
  private AccountManager? _account_manager; /* only null before prepare() */
67
67
  private Logger _logger;
68
68
  private Persona? _self_persona;
237
237
   * Create a new PersonaStore.
238
238
   *
239
239
   * Create a new persona store to store the {@link Persona}s for the contacts
240
 
   * in the Telepathy account provided by `account`.
 
240
   * in the Telepathy account provided by ``account``.
241
241
   *
242
242
   * @param account the Telepathy account being represented by the persona store
243
243
   */
395
395
      else
396
396
        this.trust_level = PersonaStoreTrust.PARTIAL;
397
397
 
 
398
      this._emit_personas_changed (null, this._persona_set);
 
399
 
398
400
      this._personas = new HashMap<string, Persona> ();
399
401
      this._personas_ro = this._personas.read_only_view;
400
402
      this._persona_set = new HashSet<Persona> ();
433
435
    {
434
436
      debug ("Removing store %s (%p)", this.id, this);
435
437
      this._emit_personas_changed (null, this._persona_set);
436
 
      this._cache.clear_cache ();
 
438
      this._cache.clear_cache.begin ();
437
439
      this.removed ();
438
440
    }
439
441
 
742
744
 
743
745
      this._conn = this.account.connection;
744
746
 
 
747
      /* Connect signals early so that cleaning up is easier if the connection
 
748
       * is disconnected during the 'yield' below. */
 
749
      this._conn.notify["self-contact"].connect (
 
750
          this._self_contact_changed_cb);
 
751
      this._conn.notify["contact-list-state"].connect (
 
752
          this._contact_list_state_changed_cb);
 
753
 
 
754
      /* FIXME: TpConnection still does not have high-level API for this.
 
755
       * See fd.o#14540 */
 
756
      /* We have to do this before emitting the self persona so that code which
 
757
       * checks the self persona's writeable fields gets correct values. */
 
758
      var flags = 0;
 
759
 
 
760
      try
 
761
        {
 
762
          flags = yield FolksTpLowlevel.connection_get_alias_flags_async (
 
763
              this._conn);
 
764
 
 
765
          /* It's possible for the connection to have disconnected while in
 
766
           * the async function call. (See bgo#683093.) If so, bail. */
 
767
          if (this._conn == null)
 
768
            {
 
769
              return;
 
770
            }
 
771
        }
 
772
      catch (GLib.Error e)
 
773
        {
 
774
          GLib.warning (
 
775
              /* Translators: the first parameter is the display name for
 
776
               * the Telepathy account, and the second is an error
 
777
               * message. */
 
778
              _("Failed to determine whether we can set aliases on Telepathy account '%s': %s"),
 
779
              this.display_name, e.message);
 
780
        }
 
781
 
 
782
      /* Emit all the notifications after the 'yield' just in case the
 
783
       * connection disappears during it. This makes cleaning up easier. */
745
784
      this.freeze_notify ();
746
785
      this._marshall_supported_fields ();
747
786
      this.notify_property ("supported-fields");
772
811
      this.notify_property ("can-add-personas");
773
812
      this.notify_property ("can-remove-personas");
774
813
 
775
 
      /* FIXME: TpConnection still does not have high-level API for this.
776
 
       * See fd.o#14540 */
777
 
      /* We have to do this before emitting the self persona so that code which
778
 
       * checks the self persona's writeable fields gets correct values. */
779
814
      var new_can_alias = MaybeBool.FALSE;
780
815
 
781
 
      try
782
 
        {
783
 
          var flags = yield FolksTpLowlevel.connection_get_alias_flags_async (
784
 
              this._conn);
785
 
 
786
 
          if ((flags &
787
 
               ConnectionAliasFlags.CONNECTION_ALIAS_FLAG_USER_SET) > 0)
788
 
            {
789
 
              new_can_alias = MaybeBool.TRUE;
790
 
 
791
 
              this._always_writeable_properties += "alias";
792
 
              this.notify_property ("always-writeable-properties");
793
 
            }
794
 
        }
795
 
      catch (GLib.Error e)
796
 
        {
797
 
          GLib.warning (
798
 
              /* Translators: the first parameter is the display name for
799
 
               * the Telepathy account, and the second is an error
800
 
               * message. */
801
 
              _("Failed to determine whether we can set aliases on Telepathy account '%s': %s"),
802
 
              this.display_name, e.message);
 
816
      if ((flags & ConnectionAliasFlags.CONNECTION_ALIAS_FLAG_USER_SET) > 0)
 
817
        {
 
818
          new_can_alias = MaybeBool.TRUE;
 
819
 
 
820
          this._always_writeable_properties += "alias";
 
821
          this.notify_property ("always-writeable-properties");
803
822
        }
804
823
 
805
824
      this._can_alias_personas = new_can_alias;
808
827
      this.thaw_notify ();
809
828
 
810
829
      /* Add the local user */
811
 
      this._conn.notify["self-contact"].connect (this._self_contact_changed_cb);
812
830
      this._self_contact_changed_cb (this._conn, null);
813
 
 
814
 
      this._conn.notify["contact-list-state"].connect (this._contact_list_state_changed_cb);
815
831
      this._contact_list_state_changed_cb (this._conn, null);
816
832
 
817
833
      Internal.profiling_end ("notify connection for Tpf.PersonaStore " +
1091
1107
      var personas_added = new HashSet<Persona> ();
1092
1108
      var personas_removed = new HashSet<Persona> ();
1093
1109
 
1094
 
      /* Remove old self persona if not also part of roster */
1095
 
      if (this._self_persona != null &&
1096
 
          !this._self_persona.is_in_contact_list &&
1097
 
          this._remove_persona (this._self_persona))
 
1110
      /* Remove old self persona if not also part of roster. Keep a reference
 
1111
       * to the persona so _remove_persona() doesn't unset it early. */
 
1112
      var self_persona = this._self_persona;
 
1113
 
 
1114
      if (self_persona != null &&
 
1115
          !self_persona.is_in_contact_list &&
 
1116
          this._remove_persona (self_persona))
1098
1117
        {
1099
 
          personas_removed.add (this._self_persona);
 
1118
          personas_removed.add (self_persona);
1100
1119
        }
 
1120
 
1101
1121
      this._self_persona = null;
1102
1122
 
1103
1123
      if (contact != null)
1126
1146
          new GLib.GenericArray<TelepathyGLib.Contact> ());
1127
1147
 
1128
1148
      this._got_initial_members = true;
1129
 
      this._populate_counters ();
 
1149
      this._populate_counters.begin ();
1130
1150
      this._notify_if_is_quiescent ();
1131
1151
    }
1132
1152
 
1190
1210
   *
1191
1211
   * See {@link Folks.PersonaStore.remove_persona}.
1192
1212
   *
1193
 
   * @throws Folks.PersonaStoreError.UNSUPPORTED_ON_USER if `persona` is the
 
1213
   * @throws Folks.PersonaStoreError.UNSUPPORTED_ON_USER if ``persona`` is the
1194
1214
   * local user — removing the local user isn’t supported
1195
1215
   * @throws Folks.PersonaStoreError.REMOVE_FAILED if removing the contact
1196
1216
   * failed
1238
1258
   *
1239
1259
   * See {@link Folks.PersonaStore.add_persona_from_details}.
1240
1260
   *
1241
 
   * @throws Folks.PersonaStoreError.INVALID_ARGUMENT if the `contact` key was
1242
 
   * not provided in `details`
 
1261
   * @throws Folks.PersonaStoreError.INVALID_ARGUMENT if the ``contact`` key was
 
1262
   * not provided in ``details``
1243
1263
   * @throws Folks.PersonaStoreError.STORE_OFFLINE if the CM is offline
1244
1264
   * @throws Folks.PersonaStoreError.CREATE_FAILED if adding the contact failed
1245
1265
   */
1444
1464
              _("Extended information may only be set on the user's Telepathy contact."));
1445
1465
        }
1446
1466
 
1447
 
      var info_list = this._contact_info_set_to_list (info_set);
 
1467
      var info_list = PersonaStore._contact_info_set_to_list (info_set);
1448
1468
      if (this.account.connection != null)
1449
1469
        {
1450
1470
          GLib.Error? error = null;
1554
1574
            }
1555
1575
 
1556
1576
          /* Bail if a store already exists for this account. */
1557
 
          assert (!PersonaStore._persona_stores_by_account.has_key (store.id));
 
1577
          return_if_fail (
 
1578
              !PersonaStore._persona_stores_by_account.has_key (store.id));
1558
1579
 
1559
1580
          /* Add the store. */
1560
1581
          PersonaStore._persona_stores_by_account.set (store.id, store);