libpurple/purplecontact.c

Tue, 20 Feb 2024 01:23:04 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 20 Feb 2024 01:23:04 -0600
changeset 42594
eddde70cedd8
parent 42584
687260353985
child 42613
780d7efe37c2
permissions
-rw-r--r--

Create a test for verifying license headers and correct the ones that were wrong

We might want to move check_license_header.py script out to somewhere else,
but this is fine for now as we're just getting things going.

Testing Done:
Compiled with the Turtles.

Reviewed at https://reviews.imfreedom.org/r/2940/

41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
7 * source distribution.
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
9 * This library is free software; you can redistribute it and/or modify it
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
10 * under the terms of the GNU General Public License as published by the Free
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
11 * Software Foundation; either version 2 of the License, or (at your option)
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
12 * any later version.
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
14 * This library is distributed in the hope that it will be useful, but WITHOUT
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
17 * more details.
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
18 *
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
19 * You should have received a copy of the GNU General Public License along with
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
20 * this library; if not, see <https://www.gnu.org/licenses/>.
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purplecontact.h"
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
42532
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
25 #include "purpleconversationmanager.h"
41918
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
26
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
27 struct _PurpleContact {
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
28 PurpleContactInfo parent;
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
30 PurpleAccount *account;
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
31 };
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 enum {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 PROP_0,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 PROP_ACCOUNT,
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
36 N_PROPERTIES,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 };
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39
42576
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42532
diff changeset
40 G_DEFINE_FINAL_TYPE(PurpleContact, purple_contact, PURPLE_TYPE_CONTACT_INFO)
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 * Helpers
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 purple_contact_set_account(PurpleContact *contact, PurpleAccount *account) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 g_return_if_fail(PURPLE_IS_CONTACT(contact));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
50 if(g_set_object(&contact->account, account)) {
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 g_object_notify_by_pspec(G_OBJECT(contact), properties[PROP_ACCOUNT]);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 * GObject Implementation
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 purple_contact_get_property(GObject *obj, guint param_id, GValue *value,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 GParamSpec *pspec)
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 PurpleContact *contact = PURPLE_CONTACT(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 switch(param_id) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 case PROP_ACCOUNT:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 g_value_set_object(value, purple_contact_get_account(contact));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 default:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 purple_contact_set_property(GObject *obj, guint param_id, const GValue *value,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 GParamSpec *pspec)
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 PurpleContact *contact = PURPLE_CONTACT(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 switch(param_id) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 case PROP_ACCOUNT:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 purple_contact_set_account(contact, g_value_get_object(value));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 default:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 purple_contact_dispose(GObject *obj) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 PurpleContact *contact = PURPLE_CONTACT(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
94 g_clear_object(&contact->account);
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 G_OBJECT_CLASS(purple_contact_parent_class)->dispose(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 static void
41960
c8a4853205e3 Bump C standard to C99 for libpurple files and fix warnings
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41948
diff changeset
100 purple_contact_init(G_GNUC_UNUSED PurpleContact *contact) {
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 purple_contact_class_init(PurpleContactClass *klass) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 obj_class->dispose = purple_contact_dispose;
41918
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
108 obj_class->get_property = purple_contact_get_property;
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
109 obj_class->set_property = purple_contact_set_property;
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 /**
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 * PurpleContact:account:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 * The account that this contact belongs to.
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 * Since: 3.0.0
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 properties[PROP_ACCOUNT] = g_param_spec_object(
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 "account", "account",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 "The account this contact belongs to",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 PURPLE_TYPE_ACCOUNT,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 * Public API
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 PurpleContact *
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
131 purple_contact_new(PurpleAccount *account, const gchar *id) {
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133
41933
8ccd6fdc7ceb Make PurpleContact derivable
Gary Kramlich <grim@reaperworld.com>
parents: 41929
diff changeset
134 return g_object_new(
8ccd6fdc7ceb Make PurpleContact derivable
Gary Kramlich <grim@reaperworld.com>
parents: 41929
diff changeset
135 PURPLE_TYPE_CONTACT,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136 "account", account,
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
137 "id", id,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 PurpleAccount *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 purple_contact_get_account(PurpleContact *contact) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
145 return contact->account;
41918
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
146 }
42532
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
147
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
148 PurpleConversation *
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
149 purple_contact_find_dm(PurpleContact *contact, gboolean create) {
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
150 PurpleConversation *conversation = NULL;
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
151 PurpleConversationManager *manager = NULL;
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
152 const char *name = NULL;
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
153
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
154 g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
155
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
156 manager = purple_conversation_manager_get_default();
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
157 name = purple_contact_info_get_username(PURPLE_CONTACT_INFO(contact));
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
158 conversation = purple_conversation_manager_find_im(manager,
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
159 contact->account,
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
160 name);
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
161
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
162 if(PURPLE_IS_CONVERSATION(conversation)) {
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
163 return conversation;
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
164 }
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
165
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
166 if(create) {
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
167 conversation = g_object_new(
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
168 PURPLE_TYPE_CONVERSATION,
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
169 "account", contact->account,
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
170 "name", name,
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
171 "type", PurpleConversationTypeDM,
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
172 NULL);
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
173 purple_conversation_manager_register(manager, conversation);
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
174
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
175 /* The manager holds a reference, so we're just returning that. */
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
176 g_object_unref(conversation);
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
177 }
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
178
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
179 return conversation;
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
180 }

mercurial