libpurple/protocols/mxit/profile.c

Wed, 03 Jul 2013 22:18:55 +0530

author
Ankit Vani <a@nevitus.org>
date
Wed, 03 Jul 2013 22:18:55 +0530
branch
soc.2013.gobjectification
changeset 34699
09b2c9219b57
parent 33852
368feedc80cf
child 34728
8efd73063ecf
permissions
-rw-r--r--

Renamed PurpleBlistNode to PurpleBListNode

28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
6b9568572bcb 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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
4 * -- user profile's --
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * Andrew Victor <libpurple@mxit.com>
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 *
6b9568572bcb 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.
6b9568572bcb 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>
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
6b9568572bcb 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
6b9568572bcb 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
6b9568572bcb 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
6b9568572bcb 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.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
6b9568572bcb 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,
6b9568572bcb 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
6b9568572bcb 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
6b9568572bcb 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.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
6b9568572bcb 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
6b9568572bcb 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
6b9568572bcb 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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
24 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
25
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
26 #define _XOPEN_SOURCE
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
27 #include <time.h>
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
28
33844
e8edfd4e26ae MXit: Cleanup the #includes (no purple.h) so that it atleast compiles within InstantBird.
Andrew Victor <andrew.victor@mxit.com>
parents: 33831
diff changeset
29 #include "internal.h"
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31 #include "mxit.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 #include "profile.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 #include "roster.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36 /*------------------------------------------------------------------------
33555
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
37 * Return the MXit Relationship status as a string.
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
38 *
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
39 * @param id The Relationship status value (see profile.h)
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
40 * @return The relationship status as a text string.
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
41 */
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
42 const char* mxit_relationship_to_name( short id )
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
43 {
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
44 switch ( id ) {
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
45 case MXIT_RELATIONSHIP_UNKNOWN :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
46 return _( "Unknown" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
47 case MXIT_RELATIONSHIP_DONTSAY :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
48 return _( "Don't want to say" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
49 case MXIT_RELATIONSHIP_SINGLE :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
50 return _( "Single" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
51 case MXIT_RELATIONSHIP_INVOLVED :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
52 return _( "In a relationship" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
53 case MXIT_RELATIONSHIP_ENGAGED :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
54 return _( "Engaged" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
55 case MXIT_RELATIONSHIP_MARRIED :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
56 return _( "Married" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
57 case MXIT_RELATIONSHIP_COMPLICATED :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
58 return _( "It's complicated" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
59 case MXIT_RELATIONSHIP_WIDOWED :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
60 return _( "Widowed" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
61 case MXIT_RELATIONSHIP_SEPARATED :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
62 return _( "Separated" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
63 case MXIT_RELATIONSHIP_DIVORCED :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
64 return _( "Divorced" );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
65 default :
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
66 return "";
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
67 }
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
68 }
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
69
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
70 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 * Returns true if it is a valid date.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72 *
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
73 * @param bday Date-of-Birth string (YYYY-MM-DD)
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74 * @return TRUE if valid, else FALSE
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76 gboolean validateDate( const char* bday )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
77 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
78 struct tm* tm;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79 time_t t;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80 int cur_year;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 int max_days[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 char date[16];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83 int year;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84 int month;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 int day;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 /* validate length */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 if ( strlen( bday ) != 10 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92 /* validate the format */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 if ( ( !isdigit( bday[0] ) ) || ( !isdigit( bday[1] ) ) || ( !isdigit( bday[2] ) ) || ( !isdigit( bday[3] ) ) || /* year */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94 ( bday[4] != '-' ) ||
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95 ( !isdigit( bday[5] ) ) || ( !isdigit( bday[6] ) ) || /* month */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
96 ( bday[7] != '-' ) ||
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 ( !isdigit( bday[8] ) ) || ( !isdigit( bday[9] ) ) ) { /* day */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101 /* convert */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 t = time( NULL );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 tm = gmtime( &t );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104 cur_year = tm->tm_year + 1900;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105 memcpy( date, bday, 10 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 date[4] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 date[7] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108 date[10] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 year = atoi( &date[0] );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110 month = atoi( &date[5] );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
111 day = atoi( &date[8] );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
112
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
113 /* validate month */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
114 if ( ( month < 1 ) || ( month > 12 ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
115 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
117
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118 /* validate day */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
119 if ( ( day < 1 ) || ( day > max_days[month] ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
121 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
122
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
123 /* validate year */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
124 if ( ( year < ( cur_year - 100 ) ) || ( year >= cur_year ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
125 /* you are either tooo old or tooo young to join mxit... sorry */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
126 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
127 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
128
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
129 /* special case leap-year */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
130 if ( ( year % 4 != 0 ) && ( month == 2 ) && ( day == 29 ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
131 /* cannot have 29 days in February in non leap-years! */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
132 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
133 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
134
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
135 return TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
136 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
137
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
138
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
139 /*------------------------------------------------------------------------
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
140 * Calculate an Age from the date-of-birth.
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
141 *
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
142 * @param date Date-of-Birth string (YYYY-MM-DD)
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
143 * @return The age
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
144 */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
145 static int calculateAge( const char* date )
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
146 {
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
147 time_t t;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
148 struct tm now, bdate;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
149 int age;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
150
32190
7881925d0929 Don't use strlen() when you're just checking whether a string is
Mark Doliner <markdoliner@pidgin.im>
parents: 32189
diff changeset
151 if ( ( !date ) || ( !*date ) )
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
152 return 0;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
153
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
154 /* current time */
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33712
diff changeset
155 t = time( NULL );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
156 localtime_r( &t, &now );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
157
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
158 /* decode hdate */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
159 memset( &bdate, 0, sizeof( struct tm ) );
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33712
diff changeset
160 purple_str_to_time( date, FALSE, &bdate, NULL, NULL );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
161
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
162 /* calculate difference */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
163 age = now.tm_year - bdate.tm_year;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
164 if ( now.tm_mon < bdate.tm_mon ) /* is before month of birth */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
165 age--;
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33712
diff changeset
166 else if ( ( now.tm_mon == bdate.tm_mon ) && ( now.tm_mday < bdate.tm_mday ) ) /* before birthday in current month */
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
167 age--;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
168
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
169 return age;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
170 }
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
171
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
172
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
173 /*------------------------------------------------------------------------
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
174 * Returns timestamp field in date & time format (DD-MM-YYYY HH:MM:SS)
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
175 *
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
176 * @param msecs The timestamps (milliseconds since epoch)
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
177 * @return Date & Time in a display'able format.
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
178 */
30563
fc5b108112ae Make MXit compile in a mingw cross-compile environment.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 30522
diff changeset
179 static const char* datetime( gint64 msecs )
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30563
diff changeset
180 {
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31294
diff changeset
181 time_t secs = msecs / 1000;
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
182
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31294
diff changeset
183 struct tm t;
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31294
diff changeset
184 localtime_r( &secs, &t );
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
185
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
186 return purple_utf8_strftime( "%d-%m-%Y %H:%M:%S", &t );
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
187 }
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
188
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
189
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
190 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
191 * Display the profile information.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
192 *
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
193 * @param session The MXit session object
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
194 * @param username The username who's profile information this is
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
195 * @param profile The profile
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
196 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
197 void mxit_show_profile( struct MXitSession* session, const char* username, struct MXitProfile* profile )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
198 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
199 PurpleNotifyUserInfo* info = purple_notify_user_info_new();
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
200 struct contact* contact = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
201 PurpleBuddy* buddy;
31844
57277e9c2049 Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
Andrew Victor <andrew.victor@mxit.com>
parents: 31843
diff changeset
202 gchar* tmp = NULL;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
203
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
204 buddy = purple_find_buddy( session->acc, username );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
205 if ( buddy ) {
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
206 purple_notify_user_info_add_pair_plaintext( info, _( "Alias" ), purple_buddy_get_alias( buddy ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
207 purple_notify_user_info_add_section_break( info );
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33712
diff changeset
208 contact = purple_buddy_get_protocol_data( buddy );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
209 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
210
32211
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
211 purple_notify_user_info_add_pair_plaintext( info, _( "Display Name" ), profile->nickname );
31844
57277e9c2049 Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
Andrew Victor <andrew.victor@mxit.com>
parents: 31843
diff changeset
212
57277e9c2049 Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
Andrew Victor <andrew.victor@mxit.com>
parents: 31843
diff changeset
213 tmp = g_strdup_printf("%s (%i)", profile->birthday, calculateAge( profile->birthday ) );
32211
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
214 purple_notify_user_info_add_pair_plaintext( info, _( "Birthday" ), tmp );
31844
57277e9c2049 Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
Andrew Victor <andrew.victor@mxit.com>
parents: 31843
diff changeset
215 g_free( tmp );
57277e9c2049 Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
Andrew Victor <andrew.victor@mxit.com>
parents: 31843
diff changeset
216
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
217 purple_notify_user_info_add_pair_plaintext( info, _( "Gender" ), profile->male ? _( "Male" ) : _( "Female" ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
218
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
219 /* optional information */
32211
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
220 purple_notify_user_info_add_pair_plaintext( info, _( "First Name" ), profile->firstname );
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
221 purple_notify_user_info_add_pair_plaintext( info, _( "Last Name" ), profile->lastname );
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
222
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
223 purple_notify_user_info_add_pair_plaintext( info, _( "Country" ), profile->regcountry );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
224
32211
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
225 if ( *profile->aboutme )
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
226 purple_notify_user_info_add_pair_plaintext( info, _( "About Me" ), profile->aboutme );
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
227
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
228 if ( *profile->whereami )
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
229 purple_notify_user_info_add_pair_plaintext( info, _( "Where I Live" ), profile->whereami );
31703
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31501
diff changeset
230
33555
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
231 purple_notify_user_info_add_pair_plaintext( info, _( "Relationship Status" ), mxit_relationship_to_name( profile->relationship ) );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 31866
diff changeset
232
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
233 purple_notify_user_info_add_section_break( info );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
234
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
235 if ( contact ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
236 /* presence */
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
237 purple_notify_user_info_add_pair_plaintext( info, _( "Status" ), mxit_convert_presence_to_name( contact->presence ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
238
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
239 /* last online */
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
240 if ( contact->presence == MXIT_PRESENCE_OFFLINE )
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
241 purple_notify_user_info_add_pair_plaintext( info, _( "Last Online" ), ( profile->lastonline == 0 ) ? _( "Unknown" ) : datetime( profile->lastonline ) );
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
242
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
243 /* mood */
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30563
diff changeset
244 if ( contact->mood != MXIT_MOOD_NONE )
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
245 purple_notify_user_info_add_pair_plaintext( info, _( "Mood" ), mxit_convert_mood_to_name( contact->mood ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
246 else
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
247 purple_notify_user_info_add_pair_plaintext( info, _( "Mood" ), _( "None" ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
248
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
249 /* status message */
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
250 if ( contact->statusMsg ) {
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
251 /* TODO: Check whether it's correct to call add_pair_html,
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
252 or if we should be using add_pair_plaintext */
32191
a4668d9dc8d1 Rename purple_notify_user_info_add_pair to
Mark Doliner <markdoliner@pidgin.im>
parents: 32190
diff changeset
253 purple_notify_user_info_add_pair_html( info, _( "Status Message" ), contact->statusMsg );
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
254 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
255
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
256 /* subscription type */
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
257 purple_notify_user_info_add_pair_plaintext( info, _( "Subscription" ), mxit_convert_subtype_to_name( contact->subtype ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
258 }
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
259 else {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
260 /* this is an invite */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
261 contact = get_mxit_invite_contact( session, username );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
262 if ( contact ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
263 /* invite found */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
264
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
265 if ( contact->msg )
32211
b46aa64aa1fb These should be using purple_notify_user_info_add_pair_plaintext().
Andrew Victor <andrew.victor@mxit.com>
parents: 32191
diff changeset
266 purple_notify_user_info_add_pair_plaintext( info, _( "Invite Message" ), contact->msg );
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
267
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
268 if ( contact->imgid ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
269 /* this invite has a avatar */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
270 char* img_text;
33052
df92c3d93904 From now on, prpls must specify images using SRC instead of ID.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32211
diff changeset
271 img_text = g_strdup_printf( "<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'>",
df92c3d93904 From now on, prpls must specify images using SRC instead of ID.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32211
diff changeset
272 contact->imgid );
32191
a4668d9dc8d1 Rename purple_notify_user_info_add_pair to
Mark Doliner <markdoliner@pidgin.im>
parents: 32190
diff changeset
273 purple_notify_user_info_add_pair_html( info, _( "Photo" ), img_text );
33712
0a6e1199c50f MXit: Fix small memory leak when viewing the profile of an incoming invite.
Andrew Victor <andrew.victor@mxit.com>
parents: 33611
diff changeset
274 g_free( img_text );
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
275 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
276
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
277 if ( contact->statusMsg ) {
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
278 /* TODO: Check whether it's correct to call add_pair_html,
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
279 or if we should be using add_pair_plaintext */
32191
a4668d9dc8d1 Rename purple_notify_user_info_add_pair to
Mark Doliner <markdoliner@pidgin.im>
parents: 32190
diff changeset
280 purple_notify_user_info_add_pair_html( info, _( "Status Message" ), contact->statusMsg );
32188
cb9cad610bc6 I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <markdoliner@pidgin.im>
parents: 32186
diff changeset
281 }
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
282 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
283 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
284
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
285 purple_notify_userinfo( session->con, username, info, NULL, NULL );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
286 purple_notify_user_info_destroy( info );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
287 }
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
288
31726
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
289
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
290 /*------------------------------------------------------------------------
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
291 * Display the profiles of search results.
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
292 *
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
293 * @param gc The connection object
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
294 * @param row The selected row from search-results
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
295 * @param user_data NULL (unused)
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
296 */
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
297 static void mxit_search_results_add_cb( PurpleConnection *gc, GList *row, gpointer user_data )
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
298 {
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
299 /* display add buddy dialog */
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
300 purple_blist_request_add_buddy( purple_connection_get_account( gc ), g_list_nth_data( row, 0 ), NULL, g_list_nth_data( row, 1 ) );
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
301 }
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
302
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
303
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
304 /*------------------------------------------------------------------------
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
305 * Display the profiles of search results.
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
306 *
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
307 * @param session The MXit session object
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
308 * @param searchType The type of search (CP_SUGGEST_*)
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
309 * @param maxResults The maximum number of results
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
310 * @param entries The list of profile entries
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
311 */
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
312 void mxit_show_search_results( struct MXitSession* session, int searchType, int maxResults, GList* entries )
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
313 {
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
314 PurpleNotifySearchResults* results;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
315 PurpleNotifySearchColumn* column;
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
316 gchar* text;
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
317
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
318 if ( !entries ) {
31721
a339d998187c Search results can contain users and services - change wording.
Andrew Victor <andrew.victor@mxit.com>
parents: 31714
diff changeset
319 mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "No results" ), _( "No contacts found." ) );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
320 return;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
321 }
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
322
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
323 results = purple_notify_searchresults_new();
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
324 if ( !results )
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
325 return;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
326
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
327 /* define columns */
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
328 column = purple_notify_searchresults_column_new( _( "UserId" ) );
32185
014a56bfee6b Use the new API in v3.0.0 to hide the UserId column in the search-results.
Andrew Victor <andrew.victor@mxit.com>
parents: 32166
diff changeset
329 purple_notify_searchresult_column_set_visible( column, FALSE );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
330 purple_notify_searchresults_column_add( results, column );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
331 column = purple_notify_searchresults_column_new( _( "Display Name" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
332 purple_notify_searchresults_column_add( results, column );
31843
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31834
diff changeset
333 column = purple_notify_searchresults_column_new( _( "First Name" ) );
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31834
diff changeset
334 purple_notify_searchresults_column_add( results, column );
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31834
diff changeset
335 column = purple_notify_searchresults_column_new( _( "Last Name" ) );
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31834
diff changeset
336 purple_notify_searchresults_column_add( results, column );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
337 column = purple_notify_searchresults_column_new( _( "Gender" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
338 purple_notify_searchresults_column_add( results, column );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
339 column = purple_notify_searchresults_column_new( _( "Age" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
340 purple_notify_searchresults_column_add( results, column );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
341 column = purple_notify_searchresults_column_new( _( "Where I live" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
342 purple_notify_searchresults_column_add( results, column );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
343
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33712
diff changeset
344 while ( entries != NULL ) {
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
345 struct MXitProfile* profile = ( struct MXitProfile *) entries->data;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
346 GList* row;
31833
ad08957902a0 Adding contacts normally and via search-results works slightly differently
Andrew Victor <andrew.victor@mxit.com>
parents: 31726
diff changeset
347 gchar* tmp = purple_base64_encode( (unsigned char *) profile->userid, strlen( profile->userid ) );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
348
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
349 /* column values */
31833
ad08957902a0 Adding contacts normally and via search-results works slightly differently
Andrew Victor <andrew.victor@mxit.com>
parents: 31726
diff changeset
350 row = g_list_append( NULL, g_strdup_printf( "#%s", tmp ) );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
351 row = g_list_append( row, g_strdup( profile->nickname ) );
31843
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31834
diff changeset
352 row = g_list_append( row, g_strdup( profile->firstname ) );
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31834
diff changeset
353 row = g_list_append( row, g_strdup( profile->lastname ) );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
354 row = g_list_append( row, g_strdup( profile->male ? "Male" : "Female" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
355 row = g_list_append( row, g_strdup_printf( "%i", calculateAge( profile->birthday ) ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
356 row = g_list_append( row, g_strdup( profile->whereami ) );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
357
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
358 purple_notify_searchresults_row_add( results, row );
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
359 entries = g_list_next( entries );
31833
ad08957902a0 Adding contacts normally and via search-results works slightly differently
Andrew Victor <andrew.victor@mxit.com>
parents: 31726
diff changeset
360
ad08957902a0 Adding contacts normally and via search-results works slightly differently
Andrew Victor <andrew.victor@mxit.com>
parents: 31726
diff changeset
361 g_free( tmp );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
362 }
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
363
31726
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
364 /* button */
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
365 purple_notify_searchresults_button_add( results, PURPLE_NOTIFY_BUTTON_INVITE, mxit_search_results_add_cb );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
366
31726
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
367 if ( searchType == CP_SUGGEST_FRIENDS )
31866
5d3065054efd Use dngettext() for two strings in the MXit protocol so that we handle
Mark Doliner <markdoliner@pidgin.im>
parents: 31844
diff changeset
368 text = g_strdup_printf( dngettext( PACKAGE, "You have %i suggested friend.", "You have %i suggested friends.", maxResults ), maxResults );
31726
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
369 else
31866
5d3065054efd Use dngettext() for two strings in the MXit protocol so that we handle
Mark Doliner <markdoliner@pidgin.im>
parents: 31844
diff changeset
370 text = g_strdup_printf( dngettext( PACKAGE, "We found %i contact that matches your search.", "We found %i contacts that match your search.", maxResults ), maxResults );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
371
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
372 purple_notify_searchresults( session->con, NULL, text, NULL, results, NULL, NULL );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
373
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33712
diff changeset
374 g_free( text );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
375 }

mercurial