libpurple/protocols/mxit/profile.c

Sun, 12 Jun 2011 17:52:59 +0000

author
Mark Doliner <markdoliner@pidgin.im>
date
Sun, 12 Jun 2011 17:52:59 +0000
changeset 31866
5d3065054efd
parent 31844
57277e9c2049
child 32088
4c1b703def6f
child 32166
7408361876cc
permissions
-rw-r--r--

Use dngettext() for two strings in the MXit protocol so that we handle
the plural case(s) correctly

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
29106
51c7b2177e42 Fix all the remaining files for which internal.h doesn't end up being the first include.
Paul Aurich <darkrain42@pidgin.im>
parents: 28841
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 #include "purple.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 #include "mxit.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 #include "profile.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34 #include "roster.h"
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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38 * 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
39 *
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
40 * @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
41 * @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
42 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 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
44 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 struct tm* tm;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46 time_t t;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
47 int cur_year;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
48 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
49 char date[16];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 int year;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
51 int month;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 int day;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
54 /* validate length */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55 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
56 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 /* validate the format */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
60 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
61 ( bday[4] != '-' ) ||
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
62 ( !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
63 ( bday[7] != '-' ) ||
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64 ( !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
65 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68 /* convert */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
69 t = time( NULL );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70 tm = gmtime( &t );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 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
72 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
73 date[4] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74 date[7] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 date[10] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76 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
77 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
78 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
79
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80 /* validate month */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 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
82 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 /* validate day */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86 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
87 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 /* validate year */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91 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
92 /* 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
93 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
96 /* 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
97 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
98 /* 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
99 return FALSE;
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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 return TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 /*------------------------------------------------------------------------
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
107 * Calculate an Age from the date-of-birth.
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
108 *
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
109 * @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
110 * @return The age
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
111 */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
112 static int calculateAge( const char* date )
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
113 {
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
114 time_t t;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
115 struct tm now, bdate;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
116 int age;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
117
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
118 if ( ( !date ) || ( strlen( date ) == 0 ) )
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
119 return 0;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
120
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
121 /* current time */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
122 t = time(NULL);
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
123 localtime_r( &t, &now );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
124
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
125 /* decode hdate */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
126 memset( &bdate, 0, sizeof( struct tm ) );
31732
6a5ede69e723 Use purple_str_to_time() instead of strptime(), which doesn't exist on Windows.
Daniel Atallah <datallah@pidgin.im>
parents: 31726
diff changeset
127 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
128
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
129 /* calculate difference */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
130 age = now.tm_year - bdate.tm_year;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
131 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
132 age--;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
133 else if ( (now.tm_mon == bdate.tm_mon ) && ( now.tm_mday < bdate.tm_mday ) ) /* before birthday in current month */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
134 age--;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
135
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
136 return age;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
137 }
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
138
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
139
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
140 /*------------------------------------------------------------------------
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
141 * 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
142 *
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
143 * @param msecs The timestamps (milliseconds since epoch)
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
144 * @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
145 */
30563
fc5b108112ae Make MXit compile in a mingw cross-compile environment.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 30522
diff changeset
146 static const char* datetime( gint64 msecs )
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30563
diff changeset
147 {
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
148 time_t secs = msecs / 1000;
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
149
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
150 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
151 localtime_r( &secs, &t );
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
152
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
153 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
154 }
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
155
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
156
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
157 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
158 * 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
159 *
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
160 * @param session The MXit session object
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
161 * @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
162 * @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
163 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
164 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
165 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
166 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
167 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
168 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
169 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
170
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
171 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
172 if ( buddy ) {
29667
9c7cdbf30435 struct hiding updates for mxit
Gary Kramlich <grim@reaperworld.com>
parents: 29106
diff changeset
173 purple_notify_user_info_add_pair( 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
174 purple_notify_user_info_add_section_break( info );
29667
9c7cdbf30435 struct hiding updates for mxit
Gary Kramlich <grim@reaperworld.com>
parents: 29106
diff changeset
175 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
176 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
177
30371
a307496582ab Implemented new naming conventions
Pieter Loubser <pieter.loubser@mxit.com>
parents: 30211
diff changeset
178 purple_notify_user_info_add_pair( 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
179
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
180 tmp = g_strdup_printf("%s (%i)", profile->birthday, calculateAge( profile->birthday ) );
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
181 purple_notify_user_info_add_pair( info, _( "Birthday" ), 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
182 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
183
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
184 purple_notify_user_info_add_pair( info, _( "Gender" ), profile->male ? _( "Male" ) : _( "Female" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
185
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
186 /* optional information */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
187 purple_notify_user_info_add_pair( info, _( "First Name" ), profile->firstname );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
188 purple_notify_user_info_add_pair( info, _( "Last Name" ), profile->lastname );
30211
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30210
diff changeset
189 purple_notify_user_info_add_pair( 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
190
31703
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31501
diff changeset
191 if ( strlen( profile->aboutme ) > 0 )
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31501
diff changeset
192 purple_notify_user_info_add_pair( info, _( "About Me" ), profile->aboutme );
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31501
diff changeset
193 if ( strlen( profile->whereami ) > 0 )
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31501
diff changeset
194 purple_notify_user_info_add_pair( info, _( "Where I Live" ), profile->whereami );
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31501
diff changeset
195
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
196 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
197
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
198 if ( contact ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
199 /* presence */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
200 purple_notify_user_info_add_pair( info, _( "Status" ), mxit_convert_presence_to_name( contact->presence ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
201
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
202 /* last online */
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
203 if ( contact->presence == MXIT_PRESENCE_OFFLINE )
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
204 purple_notify_user_info_add_pair( info, _( "Last Online" ), ( profile->lastonline == 0 ) ? _( "Unknown" ) : datetime( profile->lastonline ) );
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
205
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
206 /* mood */
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30563
diff changeset
207 if ( contact->mood != MXIT_MOOD_NONE )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
208 purple_notify_user_info_add_pair( info, _( "Mood" ), mxit_convert_mood_to_name( contact->mood ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
209 else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
210 purple_notify_user_info_add_pair( info, _( "Mood" ), _( "None" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
211
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
212 /* status message */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
213 if ( contact->statusMsg )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
214 purple_notify_user_info_add_pair( info, _( "Status Message" ), contact->statusMsg );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
215
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
216 /* subscription type */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
217 purple_notify_user_info_add_pair( info, _( "Subscription" ), mxit_convert_subtype_to_name( contact->subtype ) );
30211
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30210
diff changeset
218
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30210
diff changeset
219 /* hidden number */
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30210
diff changeset
220 purple_notify_user_info_add_pair( info, _( "Hidden Number" ), ( contact->flags & MXIT_CFLAG_HIDDEN ) ? _( "Yes" ) : _( "No" ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
221 }
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
222 else {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
223 /* this is an invite */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
224 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
225 if ( contact ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
226 /* invite found */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
227
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
228 if ( contact->msg )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
229 purple_notify_user_info_add_pair( info, _( "Invite Message" ), contact->msg );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
230
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
231 if ( contact->imgid ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
232 /* this invite has a avatar */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
233 char* img_text;
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
234 img_text = g_strdup_printf( "<img id='%d'>", contact->imgid );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
235 purple_notify_user_info_add_pair( info, _( "Photo" ), img_text );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
236 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
237
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
238 if ( contact->statusMsg )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
239 purple_notify_user_info_add_pair( info, _( "Status Message" ), contact->statusMsg );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
240 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
241 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
242
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
243 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
244 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
245 }
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
246
31726
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
247
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
248 /*------------------------------------------------------------------------
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
249 * Display the profiles of search results.
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
250 *
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
251 * @param gc The connection object
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
252 * @param row The selected row from search-results
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
253 * @param user_data NULL (unused)
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
254 */
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
255 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
256 {
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
257 /* display add buddy dialog */
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
258 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
259 }
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
260
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
261
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
262 /*------------------------------------------------------------------------
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
263 * Display the profiles of search results.
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
264 *
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
265 * @param session The MXit session object
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
266 * @param searchType The type of search (CP_SUGGEST_*)
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
267 * @param maxResults The maximum number of results
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
268 * @param entries The list of profile entries
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
269 */
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
270 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
271 {
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
272 PurpleNotifySearchResults* results;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
273 PurpleNotifySearchColumn* column;
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
274 gchar* text;
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
275
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
276 if ( !entries ) {
31721
a339d998187c Search results can contain users and services - change wording.
Andrew Victor <andrew.victor@mxit.com>
parents: 31714
diff changeset
277 mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "No results" ), _( "No contacts found." ) );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
278 return;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
279 }
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
280
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
281 results = purple_notify_searchresults_new();
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
282 if ( !results )
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
283 return;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
284
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
285 /* define columns */
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
286 column = purple_notify_searchresults_column_new( _( "UserId" ) );
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
287 purple_notify_searchresults_column_add( results, column );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
288 column = purple_notify_searchresults_column_new( _( "Display Name" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
289 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
290 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
291 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
292 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
293 purple_notify_searchresults_column_add( results, column );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
294 column = purple_notify_searchresults_column_new( _( "Gender" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
295 purple_notify_searchresults_column_add( results, column );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
296 column = purple_notify_searchresults_column_new( _( "Age" ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
297 purple_notify_searchresults_column_add( results, column );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
298 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
299 purple_notify_searchresults_column_add( results, column );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
300
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
301 while (entries != NULL) {
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
302 struct MXitProfile* profile = ( struct MXitProfile *) entries->data;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
303 GList* row;
31833
ad08957902a0 Adding contacts normally and via search-results works slightly differently
Andrew Victor <andrew.victor@mxit.com>
parents: 31726
diff changeset
304 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
305
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
306 /* column values */
31833
ad08957902a0 Adding contacts normally and via search-results works slightly differently
Andrew Victor <andrew.victor@mxit.com>
parents: 31726
diff changeset
307 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
308 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
309 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
310 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
311 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
312 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
313 row = g_list_append( row, g_strdup( profile->whereami ) );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
314
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
315 purple_notify_searchresults_row_add( results, row );
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
316 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
317
ad08957902a0 Adding contacts normally and via search-results works slightly differently
Andrew Victor <andrew.victor@mxit.com>
parents: 31726
diff changeset
318 g_free( tmp );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
319 }
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
320
31726
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
321 /* button */
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
322 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
323
31726
844d4c4d7307 Improve searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31721
diff changeset
324 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
325 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
326 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
327 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
328
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
329 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
330
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
331 g_free( text);
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
332 }

mercurial