~ubuntu-branches/ubuntu/precise/empathy/precise

« back to all changes in this revision

Viewing changes to libempathy/empathy-contact.c

Tags: upstream-0.21.90
ImportĀ upstreamĀ versionĀ 0.21.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
#include <glib/gi18n.h>
31
31
 
 
32
#include <telepathy-glib/util.h>
 
33
 
32
34
#include "empathy-contact.h"
33
35
#include "empathy-utils.h"
34
36
#include "empathy-debug.h"
45
47
        gchar              *name;
46
48
        EmpathyAvatar      *avatar;
47
49
        McAccount          *account;
48
 
        EmpathyPresence    *presence;
 
50
        McPresence          presence;
 
51
        gchar              *presence_message;
49
52
        guint               handle;
50
53
        EmpathyCapabilities capabilities;
51
54
        gboolean            is_user;
72
75
        PROP_AVATAR,
73
76
        PROP_ACCOUNT,
74
77
        PROP_PRESENCE,
 
78
        PROP_PRESENCE_MESSAGE,
75
79
        PROP_GROUPS,
76
80
        PROP_SUBSCRIPTION,
77
81
        PROP_HANDLE,
124
128
 
125
129
        g_object_class_install_property (object_class,
126
130
                                         PROP_PRESENCE,
127
 
                                         g_param_spec_object ("presence",
128
 
                                                              "Contact presence",
129
 
                                                              "Presence of contact",
130
 
                                                              EMPATHY_TYPE_PRESENCE,
 
131
                                         g_param_spec_uint ("presence",
 
132
                                                            "Contact presence",
 
133
                                                            "Presence of contact",
 
134
                                                            MC_PRESENCE_UNSET,
 
135
                                                            LAST_MC_PRESENCE,
 
136
                                                            MC_PRESENCE_UNSET,
 
137
                                                            G_PARAM_READWRITE));
 
138
 
 
139
        g_object_class_install_property (object_class,
 
140
                                         PROP_PRESENCE_MESSAGE,
 
141
                                         g_param_spec_string ("presence-message",
 
142
                                                              "Contact presence message",
 
143
                                                              "Presence message of contact",
 
144
                                                              NULL,
131
145
                                                              G_PARAM_READWRITE));
132
 
 
133
146
        g_object_class_install_property (object_class,
134
147
                                         PROP_HANDLE,
135
148
                                         g_param_spec_uint ("handle",
176
189
 
177
190
        g_free (priv->name);
178
191
        g_free (priv->id);
 
192
        g_free (priv->presence_message);
179
193
 
180
194
        if (priv->avatar) {
181
195
                empathy_avatar_unref (priv->avatar);
182
196
        }
183
197
 
184
 
        if (priv->presence) {
185
 
                g_object_unref (priv->presence);
186
 
        }
187
 
 
188
198
        if (priv->account) {
189
199
                g_object_unref (priv->account);
190
200
        }
218
228
                g_value_set_object (value, priv->account);
219
229
                break;
220
230
        case PROP_PRESENCE:
221
 
                g_value_set_object (value, priv->presence);
 
231
                g_value_set_uint (value, priv->presence);
 
232
                break;
 
233
        case PROP_PRESENCE_MESSAGE:
 
234
                g_value_set_string (value, priv->presence_message);
222
235
                break;
223
236
        case PROP_HANDLE:
224
237
                g_value_set_uint (value, priv->handle);
264
277
                break;
265
278
        case PROP_PRESENCE:
266
279
                empathy_contact_set_presence (EMPATHY_CONTACT (object),
267
 
                                             EMPATHY_PRESENCE (g_value_get_object (value)));
 
280
                                              g_value_get_uint (value));
 
281
                break;
 
282
        case PROP_PRESENCE_MESSAGE:
 
283
                empathy_contact_set_presence_message (EMPATHY_CONTACT (object),
 
284
                                                      g_value_get_string (value));
268
285
                break;
269
286
        case PROP_HANDLE:
270
287
                empathy_contact_set_handle (EMPATHY_CONTACT (object),
451
468
        g_object_notify (G_OBJECT (contact), "account");
452
469
}
453
470
 
454
 
EmpathyPresence *
 
471
McPresence
455
472
empathy_contact_get_presence (EmpathyContact *contact)
456
473
{
457
474
        EmpathyContactPriv *priv;
458
475
 
459
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
476
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), MC_PRESENCE_UNSET);
460
477
 
461
478
        priv = GET_PRIV (contact);
462
479
 
464
481
}
465
482
 
466
483
void
467
 
empathy_contact_set_presence (EmpathyContact  *contact,
468
 
                              EmpathyPresence *presence)
 
484
empathy_contact_set_presence (EmpathyContact *contact,
 
485
                              McPresence      presence)
469
486
{
470
487
        EmpathyContactPriv *priv;
471
488
 
477
494
                return;
478
495
        }
479
496
 
480
 
        if (priv->presence) {
481
 
                g_object_unref (priv->presence);
482
 
                priv->presence = NULL;
483
 
        }
484
 
 
485
 
        if (presence) {
486
 
                priv->presence = g_object_ref (presence);
487
 
        }
 
497
        priv->presence = presence;
488
498
 
489
499
        g_object_notify (G_OBJECT (contact), "presence");
490
500
}
491
501
 
 
502
const gchar *
 
503
empathy_contact_get_presence_message (EmpathyContact *contact)
 
504
{
 
505
        EmpathyContactPriv *priv;
 
506
 
 
507
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
508
 
 
509
        priv = GET_PRIV (contact);
 
510
 
 
511
        return priv->presence_message;
 
512
}
 
513
 
 
514
void
 
515
empathy_contact_set_presence_message (EmpathyContact *contact,
 
516
                                      const gchar    *message)
 
517
{
 
518
        EmpathyContactPriv *priv = GET_PRIV (contact);
 
519
 
 
520
        g_return_if_fail (EMPATHY_IS_CONTACT (contact));
 
521
 
 
522
        if (!tp_strdiff (message, priv->presence_message)) {
 
523
                return;
 
524
        }
 
525
 
 
526
        g_free (priv->presence_message);
 
527
        priv->presence_message = g_strdup (message);
 
528
 
 
529
        g_object_notify (G_OBJECT (contact), "presence-message");
 
530
}
 
531
 
492
532
guint
493
533
empathy_contact_get_handle (EmpathyContact *contact)
494
534
{
591
631
 
592
632
        priv = GET_PRIV (contact);
593
633
 
594
 
        if (!priv->presence) {
595
 
                return FALSE;
596
 
        }
597
 
 
598
 
        return (empathy_presence_get_state (priv->presence) > MC_PRESENCE_OFFLINE);
 
634
        return (priv->presence > MC_PRESENCE_OFFLINE);
599
635
}
600
636
 
601
637
const gchar *
607
643
 
608
644
        priv = GET_PRIV (contact);
609
645
 
610
 
        if (priv->presence) {
611
 
                const gchar *status;
612
 
 
613
 
                status = empathy_presence_get_status (priv->presence);
614
 
                if (!status) {
615
 
                        McPresence state;
616
 
 
617
 
                        state = empathy_presence_get_state (priv->presence);
618
 
                        status = empathy_presence_state_get_default_status (state);
619
 
                }
620
 
 
621
 
                return status;
 
646
        if (priv->presence_message) {
 
647
                return priv->presence_message;
622
648
        }
623
649
 
624
 
        return empathy_presence_state_get_default_status (MC_PRESENCE_OFFLINE);
 
650
        return empathy_presence_get_default_message (priv->presence);
625
651
}
626
652
 
627
653
gboolean