annotate libpurple/protocols/mxit/actions.c @ 31959:efed7d3c5574

Search results can contain users and services - change wording.
author andrew.victor@mxit.com
date Tue, 12 Apr 2011 19:59:54 +0000
parents 67c2d695e8d5
children 7119b2c43637
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * MXit Protocol libPurple Plugin
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
4 * -- handle MXit plugin actions --
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * Pieter Loubser <libpurple@mxit.com>
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * (C) Copyright 2009 MXit Lifestyle (Pty) Ltd.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * <http://www.mxitlifestyle.com>
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * (at your option) any later version.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * GNU General Public License for more details.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
24 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
25
29152
259bbfb423d4 Fix all the remaining files for which internal.h doesn't end up being the first include.
Paul Aurich <paul@darkrain42.org>
parents: 29005
diff changeset
26 #include "internal.h"
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
27 #include "purple.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
28
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
29 #include "protocol.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30 #include "mxit.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31 #include "roster.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 #include "actions.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 #include "splashscreen.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34 #include "cipher.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35 #include "profile.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
39 * The user has selected to change their profile.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
40 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41 * @param gc The connection object
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42 * @param fields The fields from the request pop-up
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
44 static void mxit_profile_cb( PurpleConnection* gc, PurpleRequestFields* fields )
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46 struct MXitSession* session = (struct MXitSession*) gc->proto_data;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
47 PurpleRequestField* field = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
48 const char* name = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49 const char* bday = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 const char* err = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
51
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
52 purple_debug_info( MXIT_PLUGIN_ID, "mxit_profile_cb\n" );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
54 if ( !PURPLE_CONNECTION_IS_VALID( gc ) ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55 purple_debug_error( MXIT_PLUGIN_ID, "Unable to update profile; account offline.\n" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56 return;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 /* validate name */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
60 name = purple_request_fields_get_string( fields, "name" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
61 if ( ( !name ) || ( strlen( name ) < 3 ) ) {
30737
6d6ac5720853 Clarify error message that it is the Display Name field that is invalid.
andrew.victor@mxit.com
parents: 30719
diff changeset
62 err = _( "The Display Name you entered is invalid." );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63 goto out;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
65
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 /* validate birthdate */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67 bday = purple_request_fields_get_string( fields, "bday" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68 if ( ( !bday ) || ( strlen( bday ) < 10 ) || ( !validateDate( bday ) ) ) {
28999
cfde83c57a98 The MXit guy seems to like spaces between his parenthesis, so I'll be
Mark Doliner <mark@kingant.net>
parents: 28994
diff changeset
69 err = _( "The birthday you entered is invalid. The correct format is: 'YYYY-MM-DD'." );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70 goto out;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
73 out:
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74 if ( !err ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 struct MXitProfile* profile = session->profile;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76 GString* attributes = g_string_sized_new( 128 );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
77 char attrib[512];
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
78 unsigned int acount = 0;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 /* update name */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 g_strlcpy( profile->nickname, name, sizeof( profile->nickname ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
83 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FULLNAME, CP_PROFILE_TYPE_UTF8, profile->nickname );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86
31956
cce18a0ff43a Due to the new alpha-numeric loginnames and auto-generated userId's the
andrew.victor@mxit.com
parents: 31955
diff changeset
87 /* force hidden if disabled */
cce18a0ff43a Due to the new alpha-numeric loginnames and auto-generated userId's the
andrew.victor@mxit.com
parents: 31955
diff changeset
88 if ( profile->hidden == FALSE ) {
cce18a0ff43a Due to the new alpha-numeric loginnames and auto-generated userId's the
andrew.victor@mxit.com
parents: 31955
diff changeset
89 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_HIDENUMBER, CP_PROFILE_TYPE_BOOL, "1" );
cce18a0ff43a Due to the new alpha-numeric loginnames and auto-generated userId's the
andrew.victor@mxit.com
parents: 31955
diff changeset
90 g_string_append( attributes, attrib );
cce18a0ff43a Due to the new alpha-numeric loginnames and auto-generated userId's the
andrew.victor@mxit.com
parents: 31955
diff changeset
91 acount++;
cce18a0ff43a Due to the new alpha-numeric loginnames and auto-generated userId's the
andrew.victor@mxit.com
parents: 31955
diff changeset
92 }
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94 /* update birthday */
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
95 g_strlcpy( profile->birthday, bday, sizeof( profile->birthday ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
96 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_BIRTHDATE, CP_PROFILE_TYPE_UTF8, profile->birthday );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 /* update gender */
29000
04b0ba94d646 Accidentally reversed this logic in an earlier commit
Mark Doliner <mark@kingant.net>
parents: 28999
diff changeset
101 profile->male = ( purple_request_fields_get_choice( fields, "male" ) != 0 );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
102 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_GENDER, CP_PROFILE_TYPE_BOOL, ( profile->male ) ? "1" : "0" );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 /* update title */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 name = purple_request_fields_get_string( fields, "title" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 profile->title[0] = '\0';
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
111 g_strlcpy( profile->title, name, sizeof( profile->title ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
112 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_TITLE, CP_PROFILE_TYPE_UTF8, profile->title );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
113 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
114 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
115
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 /* update firstname */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
117 name = purple_request_fields_get_string( fields, "firstname" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
119 profile->firstname[0] = '\0';
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
121 g_strlcpy( profile->firstname, name, sizeof( profile->firstname ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
122 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_FIRSTNAME, CP_PROFILE_TYPE_UTF8, profile->firstname );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
123 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
124 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
125
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
126 /* update lastname */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
127 name = purple_request_fields_get_string( fields, "lastname" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
128 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
129 profile->lastname[0] = '\0';
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
130 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
131 g_strlcpy( profile->lastname, name, sizeof( profile->lastname ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
132 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_LASTNAME, CP_PROFILE_TYPE_UTF8, profile->lastname );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
133 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
134 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
135
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
136 /* update email address */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
137 name = purple_request_fields_get_string( fields, "email" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
138 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
139 profile->email[0] = '\0';
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
140 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
141 g_strlcpy( profile->email, name, sizeof( profile->email ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
142 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_EMAIL, CP_PROFILE_TYPE_UTF8, profile->email );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
143 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
144 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
145
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
146 /* update mobile number */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
147 name = purple_request_fields_get_string( fields, "mobilenumber" );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
148 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
149 profile->mobilenr[0] = '\0';
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
150 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
151 g_strlcpy( profile->mobilenr, name, sizeof( profile->mobilenr ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
152 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_MOBILENR, CP_PROFILE_TYPE_UTF8, profile->mobilenr );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
153 g_string_append( attributes, attrib );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
154 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
155
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
156 /* update about me */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
157 name = purple_request_fields_get_string( fields, "aboutme" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
158 if ( !name )
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
159 profile->aboutme[0] = '\0';
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
160 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
161 g_strlcpy( profile->aboutme, name, sizeof( profile->aboutme ) );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
162 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_ABOUTME, CP_PROFILE_TYPE_UTF8, profile->aboutme );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
163 g_string_append( attributes, attrib );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
164 acount++;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
165
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
166 /* update where am i */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
167 name = purple_request_fields_get_string( fields, "whereami" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
168 if ( !name)
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
169 profile->whereami[0] = '\0';
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
170 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
171 g_strlcpy( profile->whereami, name, sizeof( profile->whereami ) );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
172 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_WHEREAMI, CP_PROFILE_TYPE_UTF8, profile->whereami );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
173 g_string_append( attributes, attrib );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
174 acount++;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
175
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
176 /* update flags */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
177 field = purple_request_fields_get_field( fields, "searchable" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
178 if ( purple_request_field_bool_get_value( field ) ) /* is searchable -> clear not-searchable flag */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
179 profile->flags &= ~CP_PROF_NOT_SEARCHABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
180 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
181 profile->flags |= CP_PROF_NOT_SEARCHABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
182 field = purple_request_fields_get_field( fields, "suggestable" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
183 if ( purple_request_field_bool_get_value( field ) ) /* is suggestable -> clear not-suggestable flag */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
184 profile->flags &= ~CP_PROF_NOT_SUGGESTABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
185 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
186 profile->flags |= CP_PROF_NOT_SUGGESTABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
187 g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%i", CP_PROFILE_FLAGS, CP_PROFILE_TYPE_LONG, profile->flags);
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
188 g_string_append( attributes, attrib );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
189 acount++;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
190
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
191 /* send the profile update to MXit */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
192 mxit_send_extprofile_update( session, NULL, acount, attributes->str );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
193 g_string_free( attributes, TRUE );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
194 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
195 else {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
196 /* show error to user */
29005
363691903201 A few other minor little translation-related fixes
Mark Doliner <mark@kingant.net>
parents: 29000
diff changeset
197 mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Profile Update Error" ), err );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
198 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
199 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
200
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
201
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
202 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
203 * Display and update the user's profile.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
204 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
205 * @param action The action object
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
206 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
207 static void mxit_profile_action( PurplePluginAction* action )
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
208 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
209 PurpleConnection* gc = (PurpleConnection*) action->context;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
210 struct MXitSession* session = (struct MXitSession*) gc->proto_data;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
211 struct MXitProfile* profile = session->profile;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
212
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
213 PurpleRequestFields* fields = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
214 PurpleRequestField* field = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
215
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
216 purple_debug_info( MXIT_PLUGIN_ID, "mxit_profile_action\n" );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
217
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
218 /* ensure that we actually have the user's profile information */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
219 if ( !profile ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
220 /* no profile information yet, so we cannot update */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
221 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Profile" ), _( "Your profile information is not yet retrieved. Please try again later." ) );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
222 return;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
223 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
224
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
225 fields = purple_request_fields_new();
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
226
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
227 /* Public information - what other users can see */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
228 {
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
229 PurpleRequestFieldGroup* public_group = purple_request_field_group_new( "Public information" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
230
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
231 /* display name */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
232 field = purple_request_field_string_new( "name", _( "Display Name" ), profile->nickname, FALSE );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
233 purple_request_field_group_add_field( public_group, field );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
234
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
235 /* birthday */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
236 field = purple_request_field_string_new( "bday", _( "Birthday" ), profile->birthday, FALSE );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
237 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
238 if ( profile->flags & CP_PROF_DOBLOCKED )
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
239 purple_request_field_string_set_editable( field, FALSE );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
240
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
241 /* gender */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
242 field = purple_request_field_choice_new( "male", _( "Gender" ), ( profile->male ) ? 1 : 0 );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
243 purple_request_field_choice_add( field, _( "Female" ) ); /* 0 */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
244 purple_request_field_choice_add( field, _( "Male" ) ); /* 1 */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
245 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
246
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
247 /* first name */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
248 field = purple_request_field_string_new( "firstname", _( "First Name" ), profile->firstname, FALSE );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
249 purple_request_field_group_add_field( public_group, field );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
250
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
251 /* last name */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
252 field = purple_request_field_string_new( "lastname", _( "Last Name" ), profile->lastname, FALSE );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
253 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
254
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
255 /* about me */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
256 field = purple_request_field_string_new( "aboutme", _( "About Me" ), profile->aboutme, FALSE);
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
257 purple_request_field_group_add_field( public_group, field );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
258
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
259 /* where I live */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
260 field = purple_request_field_string_new( "whereami", _( "Where I Live" ), profile->whereami, FALSE);
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
261 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
262
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
263 purple_request_fields_add_group( fields, public_group );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
264 }
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
265
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
266 /* Private information - what only MXit can see */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
267 {
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
268 PurpleRequestFieldGroup* private_group = purple_request_field_group_new( "Private information" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
269
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
270 /* title */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
271 field = purple_request_field_string_new( "title", _( "Title" ), profile->title, FALSE );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
272 purple_request_field_group_add_field( private_group, field );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
273
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
274 /* email */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
275 field = purple_request_field_string_new( "email", _( "Email" ), profile->email, FALSE );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
276 purple_request_field_group_add_field( private_group, field );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
277
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
278 /* mobile number */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
279 field = purple_request_field_string_new( "mobilenumber", _( "Mobile Number" ), profile->mobilenr, FALSE );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
280 purple_request_field_group_add_field( private_group, field );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
281
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
282 /* is searchable */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
283 field = purple_request_field_bool_new( "searchable", _( "Can be searched" ), ( ( profile->flags & CP_PROF_NOT_SEARCHABLE ) == 0) );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
284 purple_request_field_group_add_field( private_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
285
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
286 /* is suggestable */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
287 field = purple_request_field_bool_new( "suggestable", _( "Can be suggested" ), ( ( profile->flags & CP_PROF_NOT_SUGGESTABLE ) == 0 ) );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
288 purple_request_field_group_add_field( private_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
289
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
290 purple_request_fields_add_group( fields, private_group );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
291 }
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
292
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
293 /* (reference: "libpurple/request.h") */
31956
cce18a0ff43a Due to the new alpha-numeric loginnames and auto-generated userId's the
andrew.victor@mxit.com
parents: 31955
diff changeset
294 purple_request_fields( gc, _( "Profile" ), _( "Update your MXit Profile" ), NULL, fields, _( "Set" ),
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
295 G_CALLBACK( mxit_profile_cb ), _( "Cancel" ), NULL, purple_connection_get_account( gc ), NULL, NULL, gc );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
296 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
297
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
298
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
299 /*------------------------------------------------------------------------
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
300 * The user has selected to change their PIN.
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
301 *
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
302 * @param gc The connection object
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
303 * @param fields The fields from the request pop-up
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
304 */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
305 static void mxit_change_pin_cb( PurpleConnection* gc, PurpleRequestFields* fields )
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
306 {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
307 struct MXitSession* session = (struct MXitSession*) gc->proto_data;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
308 const char* pin = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
309 const char* pin2 = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
310 const char* err = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
311 int len;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
312 int i;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
313
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
314 if ( !PURPLE_CONNECTION_IS_VALID( gc ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
315 purple_debug_error( MXIT_PLUGIN_ID, "Unable to update PIN; account offline.\n" );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
316 return;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
317 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
318
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
319 /* validate pin */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
320 pin = purple_request_fields_get_string( fields, "pin" );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
321 if ( !pin ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
322 err = _( "The PIN you entered is invalid." );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
323 goto out;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
324 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
325 len = strlen( pin );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
326 if ( ( len < 4 ) || ( len > 10 ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
327 err = _( "The PIN you entered has an invalid length [4-10]." );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
328 goto out;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
329 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
330 for ( i = 0; i < len; i++ ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
331 if ( !g_ascii_isdigit( pin[i] ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
332 err = _( "The PIN is invalid. It should only consist of digits [0-9]." );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
333 goto out;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
334 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
335 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
336 pin2 = purple_request_fields_get_string( fields, "pin2" );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
337 if ( ( !pin2 ) || ( strcmp( pin, pin2 ) != 0 ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
338 err = _( "The two PINs you entered do not match." );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
339 goto out;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
340 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
341
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
342 out:
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
343 if ( !err ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
344 /* update PIN in account */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
345 purple_account_set_password( session->acc, pin );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
346
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
347 /* update session object */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
348 g_free( session->encpwd );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
349 session->encpwd = mxit_encrypt_password( session );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
350
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
351 /* send the update request to MXit */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
352 mxit_send_extprofile_update( session, session->encpwd, 0, NULL );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
353 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
354 else {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
355 /* show error to user */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
356 mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "PIN Update Error" ), err );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
357 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
358 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
359
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
360
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
361 /*------------------------------------------------------------------------
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
362 * Enable the user to change their PIN.
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
363 *
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
364 * @param action The action object
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
365 */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
366 static void mxit_change_pin_action( PurplePluginAction* action )
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
367 {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
368 PurpleConnection* gc = (PurpleConnection*) action->context;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
369 struct MXitSession* session = (struct MXitSession*) gc->proto_data;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
370
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
371 PurpleRequestFields* fields = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
372 PurpleRequestFieldGroup* group = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
373 PurpleRequestField* field = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
374
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
375 purple_debug_info( MXIT_PLUGIN_ID, "mxit_change_pin_action\n" );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
376
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
377 fields = purple_request_fields_new();
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
378 group = purple_request_field_group_new(NULL);
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
379 purple_request_fields_add_group(fields, group);
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
380
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
381 /* pin */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
382 field = purple_request_field_string_new( "pin", _( "PIN" ), session->acc->password, FALSE );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
383 purple_request_field_string_set_masked( field, TRUE );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
384 purple_request_field_group_add_field( group, field );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
385
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
386 /* verify pin */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
387 field = purple_request_field_string_new( "pin2", _( "Verify PIN" ), session->acc->password, FALSE );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
388 purple_request_field_string_set_masked( field, TRUE );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
389 purple_request_field_group_add_field( group, field );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
390
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
391 /* (reference: "libpurple/request.h") */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
392 purple_request_fields( gc, _( "Change PIN" ), _( "Change MXit PIN" ), NULL, fields, _( "Set" ),
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
393 G_CALLBACK( mxit_change_pin_cb ), _( "Cancel" ), NULL, purple_connection_get_account( gc ), NULL, NULL, gc );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
394 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
395
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
396
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
397 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
398 * Display the current splash-screen, or a notification pop-up if one is not available.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
399 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
400 * @param action The action object
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
401 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
402 static void mxit_splash_action( PurplePluginAction* action )
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
403 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
404 PurpleConnection* gc = (PurpleConnection*) action->context;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
405 struct MXitSession* session = (struct MXitSession*) gc->proto_data;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
406
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
407 if ( splash_current( session ) != NULL )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
408 splash_display( session );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
409 else
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
410 mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "View Splash" ), _( "There is no splash-screen currently available" ) );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
411 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
412
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
413
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
414 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
415 * Display info about the plugin.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
416 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
417 * @param action The action object
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
418 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
419 static void mxit_about_action( PurplePluginAction* action )
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
420 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
421 char version[256];
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
422
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
423 g_snprintf( version, sizeof( version ),
30422
30d0d4756fac * Separate the ClientVersion from the supported ProtocolVersion.
andrew.victor@mxit.com
parents: 30416
diff changeset
424 "MXit Client Protocol v%i.%i\n\n"
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
425 "Author:\nPieter Loubser\n\n"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
426 "Contributors:\nAndrew Victor\n\n"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
427 "Testers:\nBraeme Le Roux\n\n",
30422
30d0d4756fac * Separate the ClientVersion from the supported ProtocolVersion.
andrew.victor@mxit.com
parents: 30416
diff changeset
428 ( MXIT_CP_PROTO_VESION / 10 ), ( MXIT_CP_PROTO_VESION % 10 ) );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
429
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
430 mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "About" ), version );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
431 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
432
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
433
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
434 /*------------------------------------------------------------------------
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
435 * Request list of suggested friends.
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
436 *
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
437 * @param action The action object
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
438 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
439 static void mxit_suggested_friends_action( PurplePluginAction* action )
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
440 {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
441 PurpleConnection* gc = (PurpleConnection*) action->context;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
442 struct MXitSession* session = (struct MXitSession*) gc->proto_data;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
443 const char* profilelist[] = {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
444 CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME, CP_PROFILE_FIRSTNAME,
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
445 CP_PROFILE_LASTNAME, CP_PROFILE_REGCOUNTRY, CP_PROFILE_STATUS, CP_PROFILE_AVATAR };
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
446
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
447 mxit_send_suggest_friends( session, 20, ARRAY_SIZE( profilelist ), profilelist );
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
448 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
449
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
450
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
451 /*------------------------------------------------------------------------
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
452 * Perform contact search.
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
453 *
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
454 * @param action The action object
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
455 */
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
456 static void mxit_user_search_cb( PurpleConnection *gc, const char *input )
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
457 {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
458 struct MXitSession* session = (struct MXitSession*) gc->proto_data;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
459 const char* profilelist[] = {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
460 CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME, CP_PROFILE_FIRSTNAME,
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
461 CP_PROFILE_LASTNAME, CP_PROFILE_REGCOUNTRY, CP_PROFILE_STATUS, CP_PROFILE_AVATAR };
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
462
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
463 mxit_send_suggest_search( session, 20, input, ARRAY_SIZE( profilelist ), profilelist );
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
464 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
465
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
466
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
467 /*------------------------------------------------------------------------
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
468 * Display the search input form.
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
469 *
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
470 * @param action The action object
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
471 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
472 static void mxit_user_search_action( PurplePluginAction* action )
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
473 {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
474 PurpleConnection* gc = (PurpleConnection*) action->context;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
475
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
476 purple_request_input( gc, _( "Search for user" ),
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
477 _( "Search for a MXit contact" ),
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
478 _( "Type search information" ),
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
479 NULL, FALSE, FALSE, NULL,
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
480 _("_Search"), G_CALLBACK( mxit_user_search_cb ),
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
481 _("_Cancel"), NULL,
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
482 purple_connection_get_account( gc ), NULL, NULL,
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
483 gc);
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
484 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
485
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
486
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
487 /*------------------------------------------------------------------------
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
488 * Associate actions with the MXit plugin.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
489 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
490 * @param plugin The MXit protocol plugin
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
491 * @param context The connection context (if available)
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
492 * @return The list of plugin actions
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
493 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
494 GList* mxit_actions( PurplePlugin* plugin, gpointer context )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
495 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
496 PurplePluginAction* action = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
497 GList* m = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
498
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
499 /* display / change profile */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
500 action = purple_plugin_action_new( _( "Change Profile..." ), mxit_profile_action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
501 m = g_list_append( m, action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
502
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
503 /* change PIN */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
504 action = purple_plugin_action_new( _( "Change PIN..." ), mxit_change_pin_action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
505 m = g_list_append( m, action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
506
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
507 /* suggested friends */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
508 action = purple_plugin_action_new( _( "Suggested friends..." ), mxit_suggested_friends_action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
509 m = g_list_append( m, action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
510
31959
efed7d3c5574 Search results can contain users and services - change wording.
andrew.victor@mxit.com
parents: 31957
diff changeset
511 /* search for contacts */
efed7d3c5574 Search results can contain users and services - change wording.
andrew.victor@mxit.com
parents: 31957
diff changeset
512 action = purple_plugin_action_new( _( "Search for contacts..." ), mxit_user_search_action );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
513 m = g_list_append( m, action );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
514
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
515 /* display splash-screen */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
516 action = purple_plugin_action_new( _( "View Splash..." ), mxit_splash_action );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
517 m = g_list_append( m, action );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
518
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
519 /* display plugin version */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
520 action = purple_plugin_action_new( _( "About..." ), mxit_about_action );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
521 m = g_list_append( m, action );
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
522
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
523 return m;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
524 }