Mercurial > pidgin
annotate libpurple/protocols/mxit/profile.c @ 31497:acd92b7d8511
* More enhancements to user-searching.
* Update ChangeLog with MXit changes.
author | andrew.victor@mxit.com |
---|---|
date | Tue, 29 Mar 2011 14:43:15 +0000 |
parents | dde6f5770cd0 |
children | 80bbed4cb649 |
rev | line source |
---|---|
28526
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 |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
26 #define _XOPEN_SOURCE |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
27 #include <time.h> |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
28 |
28770
259bbfb423d4
Fix all the remaining files for which internal.h doesn't end up being the first include.
Paul Aurich <paul@darkrain42.org>
parents:
28526
diff
changeset
|
29 #include "internal.h" |
28526
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 * |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
40 * @param bday Date-of-Birth string (YYYY-MM-DD) |
28526
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 /*------------------------------------------------------------------------ |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
107 * Calculate an Age from the date-of-birth. |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
108 * |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
109 * @param date Date-of-Birth string (YYYY-MM-DD) |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
110 * @return The age |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
111 */ |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
112 static int calculateAge( const char* date ) |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
113 { |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
114 time_t t; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
115 struct tm now, bdate; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
116 int age; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
117 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
118 if ( ( !date ) || ( strlen( date ) == 0 ) ) |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
119 return 0; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
120 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
121 /* current time */ |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
122 t = time(NULL); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
123 localtime_r( &t, &now ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
124 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
125 /* decode hdate */ |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
126 memset( &bdate, 0, sizeof( struct tm ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
127 strptime( date, "%Y-%m-%d", &bdate ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
128 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
129 /* calculate difference */ |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
130 age = now.tm_year - bdate.tm_year; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
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:
31493
diff
changeset
|
132 age--; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
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:
31493
diff
changeset
|
134 age--; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
135 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
136 return age; |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
137 } |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
138 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
139 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
140 /*------------------------------------------------------------------------ |
30286 | 141 * Returns timestamp field in date & time format (DD-MM-YYYY HH:MM:SS) |
142 * | |
143 * @param msecs The timestamps (milliseconds since epoch) | |
144 * @return Date & Time in a display'able format. | |
145 */ | |
30303
65b97f3cdd01
Make MXit compile in a mingw cross-compile environment.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
30289
diff
changeset
|
146 static const char* datetime( gint64 msecs ) |
31086
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
30303
diff
changeset
|
147 { |
31298
02b510d2d014
* do not send requests too fast to the mxit server or they will start ignoring you.
pieter.loubser@mxit.com
parents:
31086
diff
changeset
|
148 time_t secs = msecs / 1000; |
30286 | 149 |
31298
02b510d2d014
* do not send requests too fast to the mxit server or they will start ignoring you.
pieter.loubser@mxit.com
parents:
31086
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:
31086
diff
changeset
|
151 localtime_r( &secs, &t ); |
30286 | 152 |
153 return purple_utf8_strftime( "%d-%m-%Y %H:%M:%S", &t ); | |
154 } | |
155 | |
156 | |
157 /*------------------------------------------------------------------------ | |
28526
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 * |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
160 * @param session The MXit session object |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
161 * @param username The username who's profile information this is |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
162 * @param profile The profile |
28526
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; |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
169 |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
170 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
|
171 if ( buddy ) { |
29331
ecc6217baa1e
struct hiding updates for mxit
Gary Kramlich <grim@reaperworld.com>
parents:
28770
diff
changeset
|
172 purple_notify_user_info_add_pair( info, _( "Alias" ), purple_buddy_get_alias( buddy ) ); |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
173 purple_notify_user_info_add_section_break( info ); |
29331
ecc6217baa1e
struct hiding updates for mxit
Gary Kramlich <grim@reaperworld.com>
parents:
28770
diff
changeset
|
174 contact = purple_buddy_get_protocol_data(buddy); |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
175 } |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
176 |
30283
b6b0c80f9dde
Implemented new naming conventions
pieter.loubser@mxit.com
parents:
29999
diff
changeset
|
177 purple_notify_user_info_add_pair( info, _( "Display Name" ), profile->nickname ); |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
178 purple_notify_user_info_add_pair( info, _( "Birthday" ), profile->birthday ); |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
179 purple_notify_user_info_add_pair( info, _( "Gender" ), profile->male ? _( "Male" ) : _( "Female" ) ); |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
180 |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
181 /* optional information */ |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
182 purple_notify_user_info_add_pair( info, _( "First Name" ), profile->firstname ); |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
183 purple_notify_user_info_add_pair( info, _( "Last Name" ), profile->lastname ); |
29999
207662bad69c
* Show the buddy's registration country in their profile.
andrew.victor@mxit.com
parents:
29998
diff
changeset
|
184 purple_notify_user_info_add_pair( info, _( "Country" ), profile->regcountry ); |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
185 |
31489 | 186 if ( strlen( profile->aboutme ) > 0 ) |
187 purple_notify_user_info_add_pair( info, _( "About Me" ), profile->aboutme ); | |
188 if ( strlen( profile->whereami ) > 0 ) | |
189 purple_notify_user_info_add_pair( info, _( "Where I Live" ), profile->whereami ); | |
190 | |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
191 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
|
192 |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
193 if ( contact ) { |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
194 /* presence */ |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
195 purple_notify_user_info_add_pair( info, _( "Status" ), mxit_convert_presence_to_name( contact->presence ) ); |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
196 |
30286 | 197 /* last online */ |
198 if ( contact->presence == MXIT_PRESENCE_OFFLINE ) | |
199 purple_notify_user_info_add_pair( info, _( "Last Online" ), ( profile->lastonline == 0 ) ? _( "Unknown" ) : datetime( profile->lastonline ) ); | |
200 | |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
201 /* mood */ |
31086
a8cc50c2279f
Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents:
30303
diff
changeset
|
202 if ( contact->mood != MXIT_MOOD_NONE ) |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
203 purple_notify_user_info_add_pair( info, _( "Mood" ), mxit_convert_mood_to_name( contact->mood ) ); |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
204 else |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
205 purple_notify_user_info_add_pair( info, _( "Mood" ), _( "None" ) ); |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
206 |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
207 /* status message */ |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
208 if ( contact->statusMsg ) |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
209 purple_notify_user_info_add_pair( info, _( "Status Message" ), contact->statusMsg ); |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
210 |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
211 /* subscription type */ |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
212 purple_notify_user_info_add_pair( info, _( "Subscription" ), mxit_convert_subtype_to_name( contact->subtype ) ); |
29999
207662bad69c
* Show the buddy's registration country in their profile.
andrew.victor@mxit.com
parents:
29998
diff
changeset
|
213 |
207662bad69c
* Show the buddy's registration country in their profile.
andrew.victor@mxit.com
parents:
29998
diff
changeset
|
214 /* hidden number */ |
207662bad69c
* Show the buddy's registration country in their profile.
andrew.victor@mxit.com
parents:
29998
diff
changeset
|
215 purple_notify_user_info_add_pair( info, _( "Hidden Number" ), ( contact->flags & MXIT_CFLAG_HIDDEN ) ? _( "Yes" ) : _( "No" ) ); |
28526
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
216 } |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
217 |
69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff
changeset
|
218 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
|
219 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
|
220 } |
31493 | 221 |
222 /*------------------------------------------------------------------------ | |
223 * Display the profiles of search results. | |
224 * | |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
225 * @param session The MXit session object |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
226 * @param searchType The type of search (CP_SUGGEST_*) |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
227 * @param maxResults The maximum number of results |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
228 * @param entries The list of profile entries |
31493 | 229 */ |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
230 void mxit_show_search_results( struct MXitSession* session, int searchType, int maxResults, GList* entries ) |
31493 | 231 { |
232 PurpleNotifySearchResults* results; | |
233 PurpleNotifySearchColumn* column; | |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
234 gchar* text; |
31493 | 235 |
236 if ( !entries ) { | |
237 mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "No results" ), _( "No users found." ) ); | |
238 return; | |
239 } | |
240 | |
241 results = purple_notify_searchresults_new(); | |
242 if ( !results ) | |
243 return; | |
244 | |
245 /* define columns */ | |
246 column = purple_notify_searchresults_column_new( _( "UserId" ) ); | |
247 purple_notify_searchresults_column_add( results, column ); | |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
248 column = purple_notify_searchresults_column_new( _( "Display Name" ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
249 purple_notify_searchresults_column_add( results, column ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
250 column = purple_notify_searchresults_column_new( _( "Gender" ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
251 purple_notify_searchresults_column_add( results, column ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
252 column = purple_notify_searchresults_column_new( _( "Age" ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
253 purple_notify_searchresults_column_add( results, column ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
254 column = purple_notify_searchresults_column_new( _( "Where I live" ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
255 purple_notify_searchresults_column_add( results, column ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
256 |
31493 | 257 while (entries != NULL) { |
258 struct MXitProfile* profile = ( struct MXitProfile *) entries->data; | |
259 GList* row; | |
260 | |
261 /* column values */ | |
262 row = g_list_append( NULL, g_strdup( profile->userid ) ); | |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
263 row = g_list_append( row, g_strdup( profile->nickname ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
264 row = g_list_append( row, g_strdup( profile->male ? "Male" : "Female" ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
265 row = g_list_append( row, g_strdup_printf( "%i", calculateAge( profile->birthday ) ) ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
266 row = g_list_append( row, g_strdup( profile->whereami ) ); |
31493 | 267 |
268 purple_notify_searchresults_row_add( results, row ); | |
269 entries = g_list_next( entries ); | |
270 } | |
271 | |
272 // TODO: add buttons | |
273 | |
31497
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
274 text = g_strdup_printf( _( "We found %i contacts that match your search." ), maxResults ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
275 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
276 purple_notify_searchresults( session->con, NULL, text, NULL, results, NULL, NULL ); |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
277 |
acd92b7d8511
* More enhancements to user-searching.
andrew.victor@mxit.com
parents:
31493
diff
changeset
|
278 g_free( text); |
31493 | 279 } |