Changeset ae3dc99 for protocols/nogaim.c


Ignore:
Timestamp:
2010-04-24T17:02:07Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
c521362
Parents:
b5b40ff (diff), f1b7711 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging stuff from mainline (1.2.6).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    rb5b40ff rae3dc99  
    3939
    4040static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
     41static char *format_timestamp( irc_t *irc, time_t msg_ts );
    4142
    4243GSList *connections;
     
    135136        extern void byahoo_initmodule();
    136137        extern void jabber_initmodule();
     138        extern void twitter_initmodule();
    137139        extern void purple_initmodule();
    138140
     
    151153#ifdef WITH_JABBER
    152154        jabber_initmodule();
     155#endif
     156
     157#ifdef WITH_TWITTER
     158        twitter_initmodule();
    153159#endif
    154160       
     
    726732{
    727733        irc_t *irc = ic->irc;
    728         char *wrapped;
     734        char *wrapped, *ts = NULL;
    729735        user_t *u;
    730736       
     
    768774            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    769775                strip_html( msg );
    770 
     776       
     777        if( set_getbool( &ic->irc->set, "display_timestamps" ) &&
     778            ( ts = format_timestamp( irc, sent_at ) ) )
     779        {
     780                char *new = g_strconcat( ts, msg, NULL );
     781                g_free( ts );
     782                ts = msg = new;
     783        }
     784       
    771785        wrapped = word_wrap( msg, 425 );
    772786        irc_msgfrom( irc, u->nick, wrapped );
    773787        g_free( wrapped );
     788        g_free( ts );
    774789}
    775790
     
    813828       
    814829        return c;
     830}
     831
     832void imcb_chat_name_hint( struct groupchat *c, const char *name )
     833{
     834        if( !c->joined )
     835        {
     836                struct im_connection *ic = c->ic;
     837                char stripped[MAX_NICK_LENGTH+1], *full_name;
     838               
     839                strncpy( stripped, name, MAX_NICK_LENGTH );
     840                stripped[MAX_NICK_LENGTH] = '\0';
     841                nick_strip( stripped );
     842                if( set_getbool( &ic->irc->set, "lcnicks" ) )
     843                        nick_lc( stripped );
     844               
     845                full_name = g_strdup_printf( "&%s", stripped );
     846               
     847                if( stripped[0] &&
     848                    nick_cmp( stripped, ic->irc->channel + 1 ) != 0 &&
     849                    irc_chat_by_channel( ic->irc, full_name ) == NULL )
     850                {
     851                        g_free( c->channel );
     852                        c->channel = full_name;
     853                }
     854                else
     855                {
     856                        g_free( full_name );
     857                }
     858        }
    815859}
    816860
     
    875919        if( c && u )
    876920        {
    877                 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped );
     921                char *ts = NULL;
     922                if( set_getbool( &ic->irc->set, "display_timestamps" ) )
     923                        ts = format_timestamp( ic->irc, sent_at );
     924                irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped );
     925                g_free( ts );
    878926        }
    879927        else
     
    10691117}
    10701118
    1071 
    1072 
     1119char *set_eval_timezone( set_t *set, char *value )
     1120{
     1121        char *s;
     1122       
     1123        if( strcmp( value, "local" ) == 0 ||
     1124            strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 )
     1125                return value;
     1126       
     1127        /* Otherwise: +/- at the beginning optional, then one or more numbers,
     1128           possibly followed by a colon and more numbers. Don't bother bound-
     1129           checking them since users are free to shoot themselves in the foot. */
     1130        s = value;
     1131        if( *s == '+' || *s == '-' )
     1132                s ++;
     1133       
     1134        /* \d+ */
     1135        if( !isdigit( *s ) )
     1136                return SET_INVALID;
     1137        while( *s && isdigit( *s ) ) s ++;
     1138       
     1139        /* EOS? */
     1140        if( *s == '\0' )
     1141                return value;
     1142       
     1143        /* Otherwise, colon */
     1144        if( *s != ':' )
     1145                return SET_INVALID;
     1146        s ++;
     1147       
     1148        /* \d+ */
     1149        if( !isdigit( *s ) )
     1150                return SET_INVALID;
     1151        while( *s && isdigit( *s ) ) s ++;
     1152       
     1153        /* EOS */
     1154        return *s == '\0' ? value : SET_INVALID;
     1155}
     1156
     1157static char *format_timestamp( irc_t *irc, time_t msg_ts )
     1158{
     1159        time_t now_ts = time( NULL );
     1160        struct tm now, msg;
     1161        char *set;
     1162       
     1163        /* If the timestamp is <= 0 or less than a minute ago, discard it as
     1164           it doesn't seem to add to much useful info and/or might be noise. */
     1165        if( msg_ts <= 0 || msg_ts > now_ts - 60 )
     1166                return NULL;
     1167       
     1168        set = set_getstr( &irc->set, "timezone" );
     1169        if( strcmp( set, "local" ) == 0 )
     1170        {
     1171                localtime_r( &now_ts, &now );
     1172                localtime_r( &msg_ts, &msg );
     1173        }
     1174        else
     1175        {
     1176                int hr, min = 0, sign = 60;
     1177               
     1178                if( set[0] == '-' )
     1179                {
     1180                        sign *= -1;
     1181                        set ++;
     1182                }
     1183                else if( set[0] == '+' )
     1184                {
     1185                        set ++;
     1186                }
     1187               
     1188                if( sscanf( set, "%d:%d", &hr, &min ) >= 1 )
     1189                {
     1190                        msg_ts += sign * ( hr * 60 + min );
     1191                        now_ts += sign * ( hr * 60 + min );
     1192                }
     1193               
     1194                gmtime_r( &now_ts, &now );
     1195                gmtime_r( &msg_ts, &msg );
     1196        }
     1197       
     1198        if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday )
     1199                return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ",
     1200                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1201        else
     1202                return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d "
     1203                                        "%02d:%02d:%02d\x02]\x02 ",
     1204                                        msg.tm_year + 1900, msg.tm_mon, msg.tm_mday,
     1205                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1206}
    10731207
    10741208/* The plan is to not allow straight calls to prpl functions anymore, but do
     
    11131247{
    11141248        char *away, *msg = NULL;
     1249       
     1250        if( ic->acc->prpl->away_states == NULL ||
     1251            ic->acc->prpl->set_away == NULL )
     1252                return 0;
    11151253       
    11161254        away = set_getstr( &ic->acc->set, "away" ) ?
Note: See TracChangeset for help on using the changeset viewer.