~ubuntu-branches/ubuntu/precise/folks/precise-201306070638

« back to all changes in this revision

Viewing changes to folks/im-details.vala

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-10-13 21:02:50 UTC
  • mfrom: (4.2.5 experimental)
  • mto: (4.2.6 experimental)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20111013210250-pgwuxw7z1cunhhhx
Tags: 0.6.3.2-2
* debian/rules: Call dh_strip for folks-tools package
* debian/gbp.conf: Switch to unstable branch
* debian/control:
  - Add libncurses5-dev build-dependency
  - Fix duplicate description
* debian/watch: Switch to .xz tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (C) 2010 Collabora Ltd.
 
3
 * Copyright (C) 2011 Philip Withnall
3
4
 *
4
5
 * This library is free software: you can redistribute it and/or modify
5
6
 * it under the terms of the GNU Lesser General Public License as published by
19
20
 */
20
21
 
21
22
using GLib;
 
23
using Gee;
22
24
 
23
25
/**
24
26
 * Errors related to IM addresses and IM address handling.
32
34
}
33
35
 
34
36
/**
 
37
 * Object representing an IM address value that can have some parameters
 
38
 * associated with it.
 
39
 *
 
40
 * See {@link Folks.AbstractFieldDetails}.
 
41
 *
 
42
 * @since 0.6.0
 
43
 */
 
44
public class Folks.ImFieldDetails : AbstractFieldDetails<string>
 
45
{
 
46
  /**
 
47
   * Create a new ImFieldDetails.
 
48
   *
 
49
   * @param value the value of the field
 
50
   * @param parameters initial parameters. See
 
51
   * {@link AbstractFieldDetails.parameters}. A `null` value is equivalent to an
 
52
   * empty map of parameters.
 
53
   *
 
54
   * @return a new ImFieldDetails
 
55
   *
 
56
   * @since 0.6.0
 
57
   */
 
58
  public ImFieldDetails (string value,
 
59
      MultiMap<string, string>? parameters = null)
 
60
    {
 
61
      this.value = value;
 
62
      if (parameters != null)
 
63
        this.parameters = parameters;
 
64
    }
 
65
 
 
66
  /**
 
67
   * {@inheritDoc}
 
68
   *
 
69
   * @since 0.6.0
 
70
   */
 
71
  public override bool equal (AbstractFieldDetails<string> that)
 
72
    {
 
73
      return base.equal<string> (that);
 
74
    }
 
75
 
 
76
  /**
 
77
   * {@inheritDoc}
 
78
   *
 
79
   * @since 0.6.0
 
80
   */
 
81
  public override uint hash ()
 
82
    {
 
83
      return base.hash ();
 
84
    }
 
85
}
 
86
 
 
87
/**
35
88
 * IM addresses exposed by an object implementing {@link PresenceDetails}.
36
89
 *
37
90
 * @since 0.1.13
39
92
public interface Folks.ImDetails : Object
40
93
{
41
94
  /**
42
 
   * A mapping of IM protocol to an ordered set of IM addresses.
 
95
   * A mapping of IM protocol to an (unordered) set of IM addresses.
43
96
   *
44
97
   * Each mapping is from an arbitrary protocol identifier to a set of IM
45
 
   * addresses on that protocol for the contact, listed in preference order.
46
 
   * The most-preferred IM address for each protocol comes first in that
47
 
   * protocol's list.
 
98
   * addresses on that protocol for the contact, listed in no particular order.
48
99
   *
49
 
   * There must be no duplicate IM addresses in each ordered set, though a given
 
100
   * There must be no duplicate IM addresses in each set, though a given
50
101
   * IM address may be present in the sets for different protocols.
51
102
   *
52
103
   * All the IM addresses must be normalised using
53
104
   * {@link ImDetails.normalise_im_address} before being added to this property.
54
105
   *
55
 
   * @since 0.3.4
 
106
   * @since 0.5.1
56
107
   */
57
 
  public abstract HashTable<string, LinkedHashSet<string>> im_addresses
 
108
  public abstract MultiMap<string, ImFieldDetails> im_addresses
58
109
    {
59
110
      get; set;
60
111
    }
61
112
 
62
113
  /**
 
114
   * Change the contact's set of IM addresses.
 
115
   *
 
116
   * It's preferred to call this rather than setting
 
117
   * {@link ImDetails.im_addresses} directly, as this method gives error
 
118
   * notification and will only return once the IM addresses have been written
 
119
   * to the relevant backing store (or the operation's failed).
 
120
   *
 
121
   * @param im_addresses the new map of protocols to IM addresses
 
122
   * @throws PropertyError if setting the IM addresses failed
 
123
   * @since 0.6.2
 
124
   */
 
125
  public virtual async void change_im_addresses (
 
126
      MultiMap<string, ImFieldDetails> im_addresses) throws PropertyError
 
127
    {
 
128
      /* Default implementation. */
 
129
      throw new PropertyError.NOT_WRITEABLE (
 
130
          _("IM addresses are not writeable on this contact."));
 
131
    }
 
132
 
 
133
  /**
63
134
   * Normalise an IM address so that it's suitable for string comparison.
64
135
   *
65
136
   * IM addresses for various protocols can be represented in different ways,
67
138
   * of IM addresses to work, the IM addresses must be normalised beforehand.
68
139
   *
69
140
   * If the provided IM address is invalid,
70
 
   * {@link Folks.ImDetailsError.INVALID_IM_ADDRESS} will be thrown. Note that this
71
 
   * isn't guaranteed to be thrown for all invalid addresses, but if it is
 
141
   * {@link Folks.ImDetailsError.INVALID_IM_ADDRESS} will be thrown. Note that
 
142
   * this isn't guaranteed to be thrown for all invalid addresses, but if it is
72
143
   * thrown, the address is guaranteed to be invalid.
73
144
   *
74
145
   * @param im_address the address to normalise
80
151
  public static string normalise_im_address (string im_address, string protocol)
81
152
      throws Folks.ImDetailsError
82
153
    {
83
 
      string normalised;
84
 
 
85
154
      if (protocol == "aim" || protocol == "myspace")
86
155
        {
87
 
          normalised = im_address.replace (" ", "").down ();
 
156
          return im_address.replace (" ", "").down ().normalize ();
88
157
        }
89
158
      else if (protocol == "irc" || protocol == "yahoo" ||
90
159
          protocol == "yahoojp" || protocol == "groupwise")
91
160
        {
92
 
          normalised = im_address.down ();
 
161
          return im_address.down ().normalize ();
93
162
        }
94
163
      else if (protocol == "jabber")
95
164
        {
145
214
            node = node.down ();
146
215
 
147
216
          /* Build a new JID */
 
217
          string normalised = null;
 
218
 
148
219
          if (node != null && resource != null)
149
220
            {
150
221
              normalised = "%s@%s/%s".printf (node, domain, resource);
164
235
                  _("The IM address '%s' could not be understood."),
165
236
                  im_address);
166
237
            }
 
238
 
 
239
          return normalised.normalize (-1, NormalizeMode.NFKC);
167
240
        }
168
241
      else
169
242
        {
170
243
          /* Fallback */
171
 
          normalised = im_address;
 
244
          return im_address.normalize ();
172
245
        }
173
 
 
174
 
      return normalised.normalize ();
175
246
    }
176
247
}