annotate libpurple/protocols/mxit/profile.c @ 32514:c6943fd38d44

Remove deprecated and unused PurplePluginProtocolInfo.get_cb_away.
author andrew.victor@mxit.com
date Mon, 05 Sep 2011 21:11:07 +0000
parents d9c7126086ec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * MXit Protocol libPurple Plugin
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
4 * -- user profile's --
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * Andrew Victor <libpurple@mxit.com>
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * (C) Copyright 2009 MXit Lifestyle (Pty) Ltd.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * <http://www.mxitlifestyle.com>
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * (at your option) any later version.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * GNU General Public License for more details.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
24 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
25
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
26 #define _XOPEN_SOURCE
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
27 #include <time.h>
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
28
29152
259bbfb423d4 Fix all the remaining files for which internal.h doesn't end up being the first include.
Paul Aurich <paul@darkrain42.org>
parents: 28903
diff changeset
29 #include "internal.h"
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30 #include "purple.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 #include "mxit.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 #include "profile.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34 #include "roster.h"
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 /*------------------------------------------------------------------------
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38 * Returns true if it is a valid date.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
39 *
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
40 * @param bday Date-of-Birth string (YYYY-MM-DD)
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41 * @return TRUE if valid, else FALSE
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42 */
69aa4660401a 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 )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44 {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 struct tm* tm;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46 time_t t;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
47 int cur_year;
69aa4660401a 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 };
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49 char date[16];
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 int year;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
51 int month;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 int day;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
54 /* validate length */
69aa4660401a 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 ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56 return FALSE;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 /* validate the format */
69aa4660401a 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 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
61 ( bday[4] != '-' ) ||
69aa4660401a 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 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63 ( bday[7] != '-' ) ||
69aa4660401a 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 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
65 return FALSE;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68 /* convert */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
69 t = time( NULL );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70 tm = gmtime( &t );
69aa4660401a 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;
69aa4660401a 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 );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
73 date[4] = '\0';
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74 date[7] = '\0';
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 date[10] = '\0';
69aa4660401a 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] );
69aa4660401a 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] );
69aa4660401a 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] );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80 /* validate month */
69aa4660401a 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 ) ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 return FALSE;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 /* validate day */
69aa4660401a 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] ) ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 return FALSE;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 /* validate year */
69aa4660401a 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 ) ) {
69aa4660401a 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 */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 return FALSE;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95
69aa4660401a 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 */
69aa4660401a 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 ) ) {
69aa4660401a 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! */
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 return FALSE;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 return TRUE;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 /*------------------------------------------------------------------------
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
107 * Calculate an Age from the date-of-birth.
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
108 *
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
109 * @param date Date-of-Birth string (YYYY-MM-DD)
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
110 * @return The age
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
111 */
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
112 static int calculateAge( const char* date )
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
113 {
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
114 time_t t;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
115 struct tm now, bdate;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
116 int age;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
117
32365
e8d4755ef84b Don't use strlen() when you're just checking whether a string is
Mark Doliner <mark@kingant.net>
parents: 32364
diff changeset
118 if ( ( !date ) || ( !*date ) )
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
119 return 0;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
120
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
121 /* current time */
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32355
diff changeset
122 t = time( NULL );
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
123 localtime_r( &t, &now );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
124
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
125 /* decode hdate */
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
126 memset( &bdate, 0, sizeof( struct tm ) );
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32355
diff changeset
127 purple_str_to_time( date, FALSE, &bdate, NULL, NULL );
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
128
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
129 /* calculate difference */
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
130 age = now.tm_year - bdate.tm_year;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
131 if ( now.tm_mon < bdate.tm_mon ) /* is before month of birth */
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
132 age--;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
133 else if ( (now.tm_mon == bdate.tm_mon ) && ( now.tm_mday < bdate.tm_mday ) ) /* before birthday in current month */
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
134 age--;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
135
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
136 return age;
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
137 }
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
138
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
139
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
140 /*------------------------------------------------------------------------
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
141 * Returns timestamp field in date & time format (DD-MM-YYYY HH:MM:SS)
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
142 *
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
143 * @param msecs The timestamps (milliseconds since epoch)
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
144 * @return Date & Time in a display'able format.
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
145 */
30734
65b97f3cdd01 Make MXit compile in a mingw cross-compile environment.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 30720
diff changeset
146 static const char* datetime( gint64 msecs )
31534
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 30734
diff changeset
147 {
31747
02b510d2d014 * do not send requests too fast to the mxit server or they will start ignoring you.
pieter.loubser@mxit.com
parents: 31534
diff changeset
148 time_t secs = msecs / 1000;
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
149
31747
02b510d2d014 * do not send requests too fast to the mxit server or they will start ignoring you.
pieter.loubser@mxit.com
parents: 31534
diff changeset
150 struct tm t;
02b510d2d014 * do not send requests too fast to the mxit server or they will start ignoring you.
pieter.loubser@mxit.com
parents: 31534
diff changeset
151 localtime_r( &secs, &t );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
152
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
153 return purple_utf8_strftime( "%d-%m-%Y %H:%M:%S", &t );
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
154 }
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
155
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
156
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
157 /*------------------------------------------------------------------------
28903
69aa4660401a 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.
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
159 *
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
160 * @param session The MXit session object
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
161 * @param username The username who's profile information this is
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
162 * @param profile The profile
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
163 */
69aa4660401a 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 )
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
165 {
69aa4660401a 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();
69aa4660401a 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;
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
168 PurpleBuddy* buddy;
32091
5643110e51db Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
andrew.victor@mxit.com
parents: 32090
diff changeset
169 gchar* tmp = NULL;
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
170
69aa4660401a 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 );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
172 if ( buddy ) {
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
173 purple_notify_user_info_add_pair_plaintext( info, _( "Alias" ), purple_buddy_get_alias( buddy ) );
28903
69aa4660401a 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 );
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32355
diff changeset
175 contact = purple_buddy_get_protocol_data( buddy );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
176 }
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
177
32389
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
178 purple_notify_user_info_add_pair_plaintext( info, _( "Display Name" ), profile->nickname );
32091
5643110e51db Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
andrew.victor@mxit.com
parents: 32090
diff changeset
179
5643110e51db Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
andrew.victor@mxit.com
parents: 32090
diff changeset
180 tmp = g_strdup_printf("%s (%i)", profile->birthday, calculateAge( profile->birthday ) );
32389
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
181 purple_notify_user_info_add_pair_plaintext( info, _( "Birthday" ), tmp );
32091
5643110e51db Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
andrew.victor@mxit.com
parents: 32090
diff changeset
182 g_free( tmp );
5643110e51db Since we now have a calculateAge() function we might aswell also show the buddy's age when viewing their profile information.
andrew.victor@mxit.com
parents: 32090
diff changeset
183
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
184 purple_notify_user_info_add_pair_plaintext( info, _( "Gender" ), profile->male ? _( "Male" ) : _( "Female" ) );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
185
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
186 /* optional information */
32389
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
187 purple_notify_user_info_add_pair_plaintext( info, _( "First Name" ), profile->firstname );
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
188 purple_notify_user_info_add_pair_plaintext( info, _( "Last Name" ), profile->lastname );
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
189
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
190 purple_notify_user_info_add_pair_plaintext( info, _( "Country" ), profile->regcountry );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
191
32389
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
192 if ( *profile->aboutme )
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
193 purple_notify_user_info_add_pair_plaintext( info, _( "About Me" ), profile->aboutme );
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
194
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
195 if ( *profile->whereami )
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
196 purple_notify_user_info_add_pair_plaintext( info, _( "Where I Live" ), profile->whereami );
31941
ff2a8a839dbd Extensions to the user profile.
andrew.victor@mxit.com
parents: 31747
diff changeset
197
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
198 purple_notify_user_info_add_section_break( info );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
199
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
200 if ( contact ) {
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
201 /* presence */
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
202 purple_notify_user_info_add_pair_plaintext( info, _( "Status" ), mxit_convert_presence_to_name( contact->presence ) );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
203
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
204 /* last online */
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
205 if ( contact->presence == MXIT_PRESENCE_OFFLINE )
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
206 purple_notify_user_info_add_pair_plaintext( info, _( "Last Online" ), ( profile->lastonline == 0 ) ? _( "Unknown" ) : datetime( profile->lastonline ) );
30717
08d9cdac2b3c A few changes to the Profile.
andrew.victor@mxit.com
parents: 30714
diff changeset
207
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
208 /* mood */
31534
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 30734
diff changeset
209 if ( contact->mood != MXIT_MOOD_NONE )
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
210 purple_notify_user_info_add_pair_plaintext( info, _( "Mood" ), mxit_convert_mood_to_name( contact->mood ) );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
211 else
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
212 purple_notify_user_info_add_pair_plaintext( info, _( "Mood" ), _( "None" ) );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
213
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
214 /* status message */
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
215 if ( contact->statusMsg ) {
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
216 /* TODO: Check whether it's correct to call add_pair_html,
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
217 or if we should be using add_pair_plaintext */
32366
99ca503ea087 Rename purple_notify_user_info_add_pair to
Mark Doliner <mark@kingant.net>
parents: 32365
diff changeset
218 purple_notify_user_info_add_pair_html( info, _( "Status Message" ), contact->statusMsg );
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
219 }
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
220
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
221 /* subscription type */
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
222 purple_notify_user_info_add_pair_plaintext( info, _( "Subscription" ), mxit_convert_subtype_to_name( contact->subtype ) );
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
223 }
31952
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
224 else {
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
225 /* this is an invite */
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
226 contact = get_mxit_invite_contact( session, username );
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
227 if ( contact ) {
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
228 /* invite found */
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
229
32389
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
230 if ( contact->msg )
d9c7126086ec These should be using purple_notify_user_info_add_pair_plaintext().
andrew.victor@mxit.com
parents: 32366
diff changeset
231 purple_notify_user_info_add_pair_plaintext( info, _( "Invite Message" ), contact->msg );
31952
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
232
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
233 if ( contact->imgid ) {
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
234 /* this invite has a avatar */
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
235 char* img_text;
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
236 img_text = g_strdup_printf( "<img id='%d'>", contact->imgid );
32366
99ca503ea087 Rename purple_notify_user_info_add_pair to
Mark Doliner <mark@kingant.net>
parents: 32365
diff changeset
237 purple_notify_user_info_add_pair_html( info, _( "Photo" ), img_text );
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
238 g_free(img_text);
31952
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
239 }
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
240
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
241 if ( contact->statusMsg ) {
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
242 /* TODO: Check whether it's correct to call add_pair_html,
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
243 or if we should be using add_pair_plaintext */
32366
99ca503ea087 Rename purple_notify_user_info_add_pair to
Mark Doliner <mark@kingant.net>
parents: 32365
diff changeset
244 purple_notify_user_info_add_pair_html( info, _( "Status Message" ), contact->statusMsg );
32363
3322201b446f I went through all our calls to purple_notify_user_info_add_pair() and
Mark Doliner <mark@kingant.net>
parents: 32361
diff changeset
245 }
31952
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
246 }
80bbed4cb649 * extended the profile information shown for pending invites
pieter.loubser@mxit.com
parents: 31949
diff changeset
247 }
28903
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
248
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
249 purple_notify_userinfo( session->con, username, info, NULL, NULL );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
250 purple_notify_user_info_destroy( info );
69aa4660401a Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
251 }
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
252
31964
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
253
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
254 /*------------------------------------------------------------------------
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
255 * Display the profiles of search results.
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
256 *
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
257 * @param gc The connection object
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
258 * @param row The selected row from search-results
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
259 * @param user_data NULL (unused)
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
260 */
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
261 static void mxit_search_results_add_cb( PurpleConnection *gc, GList *row, gpointer user_data )
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
262 {
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
263 /* display add buddy dialog */
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
264 purple_blist_request_add_buddy( purple_connection_get_account( gc ), g_list_nth_data( row, 0 ), NULL, g_list_nth_data( row, 1 ) );
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
265 }
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
266
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
267
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
268 /*------------------------------------------------------------------------
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
269 * Display the profiles of search results.
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
270 *
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
271 * @param session The MXit session object
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
272 * @param searchType The type of search (CP_SUGGEST_*)
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
273 * @param maxResults The maximum number of results
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
274 * @param entries The list of profile entries
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
275 */
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
276 void mxit_show_search_results( struct MXitSession* session, int searchType, int maxResults, GList* entries )
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
277 {
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
278 PurpleNotifySearchResults* results;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
279 PurpleNotifySearchColumn* column;
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
280 gchar* text;
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
281
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
282 if ( !entries ) {
31959
efed7d3c5574 Search results can contain users and services - change wording.
andrew.victor@mxit.com
parents: 31952
diff changeset
283 mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "No results" ), _( "No contacts found." ) );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
284 return;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
285 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
286
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
287 results = purple_notify_searchresults_new();
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
288 if ( !results )
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
289 return;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
290
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
291 /* define columns */
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
292 column = purple_notify_searchresults_column_new( _( "UserId" ) );
32355
3fb4cad5ad2d Use the new API in v3.0.0 to hide the UserId column in the search-results.
andrew.victor@mxit.com
parents: 32338
diff changeset
293 purple_notify_searchresult_column_set_visible( column, FALSE );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
294 purple_notify_searchresults_column_add( results, column );
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
295 column = purple_notify_searchresults_column_new( _( "Display Name" ) );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
296 purple_notify_searchresults_column_add( results, column );
32090
055a33b6bf59 Also show FirstName and LastName in search-results and friend-suggestions.
andrew.victor@mxit.com
parents: 32082
diff changeset
297 column = purple_notify_searchresults_column_new( _( "First Name" ) );
055a33b6bf59 Also show FirstName and LastName in search-results and friend-suggestions.
andrew.victor@mxit.com
parents: 32082
diff changeset
298 purple_notify_searchresults_column_add( results, column );
055a33b6bf59 Also show FirstName and LastName in search-results and friend-suggestions.
andrew.victor@mxit.com
parents: 32082
diff changeset
299 column = purple_notify_searchresults_column_new( _( "Last Name" ) );
055a33b6bf59 Also show FirstName and LastName in search-results and friend-suggestions.
andrew.victor@mxit.com
parents: 32082
diff changeset
300 purple_notify_searchresults_column_add( results, column );
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
301 column = purple_notify_searchresults_column_new( _( "Gender" ) );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
302 purple_notify_searchresults_column_add( results, column );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
303 column = purple_notify_searchresults_column_new( _( "Age" ) );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
304 purple_notify_searchresults_column_add( results, column );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
305 column = purple_notify_searchresults_column_new( _( "Where I live" ) );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
306 purple_notify_searchresults_column_add( results, column );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
307
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32355
diff changeset
308 while ( entries != NULL ) {
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
309 struct MXitProfile* profile = ( struct MXitProfile *) entries->data;
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
310 GList* row;
32080
08dccf527457 Adding contacts normally and via search-results works slightly differently
andrew.victor@mxit.com
parents: 31964
diff changeset
311 gchar* tmp = purple_base64_encode( (unsigned char *) profile->userid, strlen( profile->userid ) );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
312
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
313 /* column values */
32080
08dccf527457 Adding contacts normally and via search-results works slightly differently
andrew.victor@mxit.com
parents: 31964
diff changeset
314 row = g_list_append( NULL, g_strdup_printf( "#%s", tmp ) );
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
315 row = g_list_append( row, g_strdup( profile->nickname ) );
32090
055a33b6bf59 Also show FirstName and LastName in search-results and friend-suggestions.
andrew.victor@mxit.com
parents: 32082
diff changeset
316 row = g_list_append( row, g_strdup( profile->firstname ) );
055a33b6bf59 Also show FirstName and LastName in search-results and friend-suggestions.
andrew.victor@mxit.com
parents: 32082
diff changeset
317 row = g_list_append( row, g_strdup( profile->lastname ) );
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
318 row = g_list_append( row, g_strdup( profile->male ? "Male" : "Female" ) );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
319 row = g_list_append( row, g_strdup_printf( "%i", calculateAge( profile->birthday ) ) );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
320 row = g_list_append( row, g_strdup( profile->whereami ) );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
321
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
322 purple_notify_searchresults_row_add( results, row );
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
323 entries = g_list_next( entries );
32080
08dccf527457 Adding contacts normally and via search-results works slightly differently
andrew.victor@mxit.com
parents: 31964
diff changeset
324
08dccf527457 Adding contacts normally and via search-results works slightly differently
andrew.victor@mxit.com
parents: 31964
diff changeset
325 g_free( tmp );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
326 }
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
327
31964
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
328 /* button */
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
329 purple_notify_searchresults_button_add( results, PURPLE_NOTIFY_BUTTON_INVITE, mxit_search_results_add_cb );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
330
31964
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
331 if ( searchType == CP_SUGGEST_FRIENDS )
32115
3a3af6ad3166 Use dngettext() for two strings in the MXit protocol so that we handle
Mark Doliner <mark@kingant.net>
parents: 32091
diff changeset
332 text = g_strdup_printf( dngettext( PACKAGE, "You have %i suggested friend.", "You have %i suggested friends.", maxResults ), maxResults );
31964
6b59dd656fee Improve searching.
andrew.victor@mxit.com
parents: 31959
diff changeset
333 else
32115
3a3af6ad3166 Use dngettext() for two strings in the MXit protocol so that we handle
Mark Doliner <mark@kingant.net>
parents: 32091
diff changeset
334 text = g_strdup_printf( dngettext( PACKAGE, "We found %i contact that matches your search.", "We found %i contacts that match your search.", maxResults ), maxResults );
31949
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
335
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
336 purple_notify_searchresults( session->con, NULL, text, NULL, results, NULL, NULL );
acd92b7d8511 * More enhancements to user-searching.
andrew.victor@mxit.com
parents: 31945
diff changeset
337
32361
93cb9f408df4 Whitespace changes for coding-style consistency.
andrew.victor@mxit.com
parents: 32355
diff changeset
338 g_free( text );
31945
dde6f5770cd0 Searching.
andrew.victor@mxit.com
parents: 31941
diff changeset
339 }