annotate libpurple/protocols/mxit/actions.c @ 32481:095254ccea3d

Checkin PurpleStatus API changes.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Fri, 02 Sep 2011 04:23:18 +0000
parents 4b15c5c68aa4
children f75041cb3fec
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 {
32394
4b15c5c68aa4 Don't access PurpleConnection->proto_data directly, rather use the access functions.
andrew.victor@mxit.com
parents: 32361
diff changeset
46 struct MXitSession* session = purple_connection_get_protocol_data( gc ) ;
28903
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
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 /* update birthday */
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
88 g_strlcpy( profile->birthday, bday, sizeof( profile->birthday ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
89 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
90 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
91 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 /* update gender */
29000
04b0ba94d646 Accidentally reversed this logic in an earlier commit
Mark Doliner <mark@kingant.net>
parents: 28999
diff changeset
94 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
95 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
96 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
97 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 /* update title */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 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
101 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 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
103 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
104 g_strlcpy( profile->title, name, sizeof( profile->title ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
105 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
106 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
107 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 /* update firstname */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110 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
111 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
112 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
113 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
114 g_strlcpy( profile->firstname, name, sizeof( profile->firstname ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
115 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
116 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
117 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
119 /* update lastname */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120 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
121 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
122 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
123 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
124 g_strlcpy( profile->lastname, name, sizeof( profile->lastname ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
125 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
126 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
127 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
128
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
129 /* update email address */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
130 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
131 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
132 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
133 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
134 g_strlcpy( profile->email, name, sizeof( profile->email ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
135 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
136 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
137 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
138
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
139 /* update mobile number */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
140 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
141 if ( !name )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
142 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
143 else
30719
d9e94339ca3b For safety, rather use g_strlcpy() and snprintf() where possible.
andrew.victor@mxit.com
parents: 30717
diff changeset
144 g_strlcpy( profile->mobilenr, name, sizeof( profile->mobilenr ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
145 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
146 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
147 acount++;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
148
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
149 /* update about me */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
150 name = purple_request_fields_get_string( fields, "aboutme" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
151 if ( !name )
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
152 profile->aboutme[0] = '\0';
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
153 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
154 g_strlcpy( profile->aboutme, name, sizeof( profile->aboutme ) );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
155 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
156 g_string_append( attributes, attrib );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
157 acount++;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
158
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
159 /* update where am i */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
160 name = purple_request_fields_get_string( fields, "whereami" );
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32339
diff changeset
161 if ( !name )
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
162 profile->whereami[0] = '\0';
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
163 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
164 g_strlcpy( profile->whereami, name, sizeof( profile->whereami ) );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
165 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
166 g_string_append( attributes, attrib );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
167 acount++;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
168
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
169 /* update flags */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
170 field = purple_request_fields_get_field( fields, "searchable" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
171 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
172 profile->flags &= ~CP_PROF_NOT_SEARCHABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
173 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
174 profile->flags |= CP_PROF_NOT_SEARCHABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
175 field = purple_request_fields_get_field( fields, "suggestable" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
176 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
177 profile->flags &= ~CP_PROF_NOT_SUGGESTABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
178 else
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
179 profile->flags |= CP_PROF_NOT_SUGGESTABLE;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
180 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
181 g_string_append( attributes, attrib );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
182 acount++;
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
183
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
184 /* 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
185 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
186 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
187 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
188 else {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
189 /* show error to user */
29005
363691903201 A few other minor little translation-related fixes
Mark Doliner <mark@kingant.net>
parents: 29000
diff changeset
190 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
191 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
192 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
193
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 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
196 * 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
197 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
198 * @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
199 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
200 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
201 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
202 PurpleConnection* gc = (PurpleConnection*) action->context;
32394
4b15c5c68aa4 Don't access PurpleConnection->proto_data directly, rather use the access functions.
andrew.victor@mxit.com
parents: 32361
diff changeset
203 struct MXitSession* session = purple_connection_get_protocol_data( gc );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
204 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
205
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
206 PurpleRequestFields* fields = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
207 PurpleRequestField* field = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
208
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
209 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
210
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
211 /* 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
212 if ( !profile ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
213 /* 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
214 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
215 return;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
216 }
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 fields = purple_request_fields_new();
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
219
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
220 /* Public information - what other users can see */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
221 {
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
222 PurpleRequestFieldGroup* public_group = purple_request_field_group_new( "Public information" );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
223
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
224 /* display name */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
225 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
226 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
227
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
228 /* birthday */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
229 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
230 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
231 if ( profile->flags & CP_PROF_DOBLOCKED )
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
232 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
233
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
234 /* gender */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
235 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
236 purple_request_field_choice_add( field, _( "Female" ) ); /* 0 */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
237 purple_request_field_choice_add( field, _( "Male" ) ); /* 1 */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
238 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
239
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
240 /* first name */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
241 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
242 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
243
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
244 /* last name */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
245 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
246 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
247
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
248 /* about me */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
249 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
250 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
251
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
252 /* where I live */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
253 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
254 purple_request_field_group_add_field( public_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
255
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
256 purple_request_fields_add_group( fields, public_group );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
257 }
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 /* Private information - what only MXit can see */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
260 {
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
261 PurpleRequestFieldGroup* private_group = purple_request_field_group_new( "Private information" );
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 /* title */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
264 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
265 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
266
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
267 /* email */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
268 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
269 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
270
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
271 /* mobile number */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
272 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
273 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
274
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
275 /* is searchable */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
276 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
277 purple_request_field_group_add_field( private_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
278
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
279 /* is suggestable */
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
280 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
281 purple_request_field_group_add_field( private_group, field );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
282
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
283 purple_request_fields_add_group( fields, private_group );
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
284 }
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
285
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
286 /* (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
287 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
288 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
289 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
290
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
291
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
292 /*------------------------------------------------------------------------
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
293 * 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
294 *
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
295 * @param gc The connection object
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
296 * @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
297 */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
298 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
299 {
32394
4b15c5c68aa4 Don't access PurpleConnection->proto_data directly, rather use the access functions.
andrew.victor@mxit.com
parents: 32361
diff changeset
300 struct MXitSession* session = purple_connection_get_protocol_data( gc );
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
301 const char* pin = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
302 const char* pin2 = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
303 const char* err = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
304 int len;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
305 int i;
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 if ( !PURPLE_CONNECTION_IS_VALID( gc ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
308 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
309 return;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
310 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
311
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
312 /* validate pin */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
313 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
314 if ( !pin ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
315 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
316 goto out;
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 len = strlen( pin );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
319 if ( ( len < 4 ) || ( len > 10 ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
320 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
321 goto out;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
322 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
323 for ( i = 0; i < len; i++ ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
324 if ( !g_ascii_isdigit( pin[i] ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
325 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
326 goto out;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
327 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
328 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
329 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
330 if ( ( !pin2 ) || ( strcmp( pin, pin2 ) != 0 ) ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
331 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
332 goto out;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
333 }
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 out:
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
336 if ( !err ) {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
337 /* update PIN in account */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
338 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
339
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
340 /* update session object */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
341 g_free( session->encpwd );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
342 session->encpwd = mxit_encrypt_password( session );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
343
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
344 /* send the update request to MXit */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
345 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
346 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
347 else {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
348 /* show error to user */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
349 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
350 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
351 }
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
352
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 /*------------------------------------------------------------------------
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
355 * 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
356 *
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
357 * @param action The action object
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 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
360 {
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
361 PurpleConnection* gc = (PurpleConnection*) action->context;
32394
4b15c5c68aa4 Don't access PurpleConnection->proto_data directly, rather use the access functions.
andrew.victor@mxit.com
parents: 32361
diff changeset
362 struct MXitSession* session = purple_connection_get_protocol_data( gc );
31957
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 PurpleRequestFields* fields = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
365 PurpleRequestFieldGroup* group = NULL;
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
366 PurpleRequestField* field = NULL;
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 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
369
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
370 fields = purple_request_fields_new();
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32339
diff changeset
371 group = purple_request_field_group_new( NULL );
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32339
diff changeset
372 purple_request_fields_add_group( fields, group );
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
373
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
374 /* pin */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
375 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
376 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
377 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
378
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
379 /* verify pin */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
380 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
381 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
382 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
383
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
384 /* (reference: "libpurple/request.h") */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
385 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
386 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
387 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
388
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
389
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
390 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
391 * 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
392 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
393 * @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
394 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
395 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
396 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
397 PurpleConnection* gc = (PurpleConnection*) action->context;
32394
4b15c5c68aa4 Don't access PurpleConnection->proto_data directly, rather use the access functions.
andrew.victor@mxit.com
parents: 32361
diff changeset
398 struct MXitSession* session = purple_connection_get_protocol_data( gc );
28903
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 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
401 splash_display( session );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
402 else
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
403 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
404 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
405
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 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
408 * 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
409 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
410 * @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
411 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
412 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
413 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
414 char version[256];
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
415
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31744
diff changeset
416 g_snprintf( version, sizeof( version ),
30422
30d0d4756fac * Separate the ClientVersion from the supported ProtocolVersion.
andrew.victor@mxit.com
parents: 30416
diff changeset
417 "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
418 "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
419 "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
420 "Testers:\nBraeme Le Roux\n\n",
30422
30d0d4756fac * Separate the ClientVersion from the supported ProtocolVersion.
andrew.victor@mxit.com
parents: 30416
diff changeset
421 ( 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
422
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
423 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
424 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
425
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
426
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
427 /*------------------------------------------------------------------------
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
428 * Request list of suggested friends.
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
429 *
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
430 * @param action The action object
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
431 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
432 static void mxit_suggested_friends_action( PurplePluginAction* action )
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
433 {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
434 PurpleConnection* gc = (PurpleConnection*) action->context;
32394
4b15c5c68aa4 Don't access PurpleConnection->proto_data directly, rather use the access functions.
andrew.victor@mxit.com
parents: 32361
diff changeset
435 struct MXitSession* session = purple_connection_get_protocol_data( gc );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
436 const char* profilelist[] = {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
437 CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME, CP_PROFILE_FIRSTNAME,
31963
7119b2c43637 Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
438 CP_PROFILE_LASTNAME, CP_PROFILE_REGCOUNTRY, CP_PROFILE_STATUS, CP_PROFILE_AVATAR,
7119b2c43637 Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
439 CP_PROFILE_WHEREAMI, CP_PROFILE_ABOUTME };
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
440
31963
7119b2c43637 Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
441 mxit_send_suggest_friends( session, MXIT_SEARCHRESULTS_MAX, ARRAY_SIZE( profilelist ), profilelist );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
442 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
443
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
444
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
445 /*------------------------------------------------------------------------
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
446 * Perform contact search.
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
447 *
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
448 * @param action The action object
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
449 */
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
450 static void mxit_user_search_cb( PurpleConnection *gc, const char *input )
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
451 {
32394
4b15c5c68aa4 Don't access PurpleConnection->proto_data directly, rather use the access functions.
andrew.victor@mxit.com
parents: 32361
diff changeset
452 struct MXitSession* session = purple_connection_get_protocol_data( gc );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
453 const char* profilelist[] = {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
454 CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME, CP_PROFILE_FIRSTNAME,
31963
7119b2c43637 Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
455 CP_PROFILE_LASTNAME, CP_PROFILE_REGCOUNTRY, CP_PROFILE_STATUS, CP_PROFILE_AVATAR,
7119b2c43637 Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
456 CP_PROFILE_WHEREAMI, CP_PROFILE_ABOUTME };
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
457
31963
7119b2c43637 Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
458 mxit_send_suggest_search( session, MXIT_SEARCHRESULTS_MAX, input, ARRAY_SIZE( profilelist ), profilelist );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
459 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
460
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
461
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
462 /*------------------------------------------------------------------------
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
463 * Display the search input form.
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
464 *
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
465 * @param action The action object
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
466 */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
467 static void mxit_user_search_action( PurplePluginAction* action )
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
468 {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
469 PurpleConnection* gc = (PurpleConnection*) action->context;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
470
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
471 purple_request_input( gc, _( "Search for user" ),
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
472 _( "Search for a MXit contact" ),
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
473 _( "Type search information" ),
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
474 NULL, FALSE, FALSE, NULL,
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32339
diff changeset
475 _( "_Search" ), G_CALLBACK( mxit_user_search_cb ),
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32339
diff changeset
476 _( "_Cancel" ), NULL,
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
477 purple_connection_get_account( gc ), NULL, NULL,
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32339
diff changeset
478 gc );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
479 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
480
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
481
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
482 /*------------------------------------------------------------------------
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
483 * 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
484 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
485 * @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
486 * @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
487 * @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
488 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
489 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
490 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
491 PurplePluginAction* action = NULL;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
492 GList* m = NULL;
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 /* display / change profile */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
495 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
496 m = g_list_append( m, action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
497
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
498 /* change PIN */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
499 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
500 m = g_list_append( m, action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
501
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
502 /* suggested friends */
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
503 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
504 m = g_list_append( m, action );
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
505
31959
efed7d3c5574 Search results can contain users and services - change wording.
andrew.victor@mxit.com
parents: 31957
diff changeset
506 /* search for contacts */
efed7d3c5574 Search results can contain users and services - change wording.
andrew.victor@mxit.com
parents: 31957
diff changeset
507 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
508 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
509
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
510 /* display splash-screen */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
511 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
512 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
513
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
514 /* display plugin version */
31957
67c2d695e8d5 Move the PIN-change option into a separate PluginAction.
andrew.victor@mxit.com
parents: 31956
diff changeset
515 action = purple_plugin_action_new( _( "About..." ), mxit_about_action );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
516 m = g_list_append( m, action );
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
517
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
518 return m;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
519 }