Changeset 34fbbf9 for protocols


Ignore:
Timestamp:
2010-03-06T18:22:20Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
58adb7e
Parents:
be915f5
Message:

Adapted nogaim.c. Pretty nice cleanup of away state alias handling, mostly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    rbe915f5 r34fbbf9  
    10701070}
    10711071
    1072 static char *imc_away_alias_find( GList *gcm, char *away );
     1072static char *imc_away_state_find( GList *gcm, char *away, char **message );
    10731073
    10741074int imc_set_away( struct im_connection *ic, char *away )
    10751075{
    1076         GList *m, *ms;
    1077         char *s;
    1078        
    1079         if( !away ) away = "";
    1080         ms = m = ic->acc->prpl->away_states( ic );
    1081        
    1082         while( m )
    1083         {
    1084                 if( *away )
    1085                 {
    1086                         if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
    1087                                 break;
    1088                 }
    1089                 else
    1090                 {
    1091                         if( g_strcasecmp( m->data, "Available" ) == 0 )
    1092                                 break;
    1093                         if( g_strcasecmp( m->data, "Online" ) == 0 )
    1094                                 break;
    1095                 }
    1096                 m = m->next;
    1097         }
    1098        
    1099         if( m )
    1100         {
    1101                 ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL );
    1102         }
    1103         else
    1104         {
    1105                 s = imc_away_alias_find( ms, away );
    1106                 if( s )
    1107                 {
    1108                         ic->acc->prpl->set_away( ic, s, away );
    1109                         if( set_getbool( &ic->irc->set, "debug" ) )
    1110                                 imcb_log( ic, "Setting away state to %s", s );
    1111                 }
    1112                 else
    1113                         ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away );
    1114         }
    1115        
    1116         return( 1 );
     1076        char *s = NULL, *msg = away;
     1077       
     1078        if( away && *away )
     1079        {
     1080                GList *m = ic->acc->prpl->away_states( ic );
     1081                s = imc_away_state_find( m, away, &msg ) ? : m->data;
     1082        }
     1083       
     1084        if( set_getbool( &ic->irc->set, "debug" ) )
     1085                imcb_log( ic, "Setting away state to %s", s );
     1086       
     1087        ic->acc->prpl->set_away( ic, s, ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? msg : NULL );
     1088       
     1089        return 1;
    11171090}
    11181091
     
    11291102};
    11301103
    1131 static char *imc_away_alias_find( GList *gcm, char *away )
     1104static char *imc_away_state_find( GList *gcm, char *away, char **message )
    11321105{
    11331106        GList *m;
    11341107        int i, j;
    11351108       
     1109        for( m = gcm; m; m = m->next )
     1110                if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
     1111                {
     1112                        /* At least the Yahoo! module works better if message
     1113                           contains no data unless it adds something to what
     1114                           we have in state already. */
     1115                        if( strlen( m->data ) == strlen( away ) )
     1116                                *message = NULL;
     1117                       
     1118                        return m->data;
     1119                }
     1120       
    11361121        for( i = 0; *imc_away_alias_list[i]; i ++ )
    11371122        {
     1123                int keep_message;
     1124               
    11381125                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    11391126                        if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 )
     1127                        {
     1128                                keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );
    11401129                                break;
     1130                        }
    11411131               
    11421132                if( !imc_away_alias_list[i][j] )        /* If we reach the end, this row */
     
    11461136                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    11471137                {
    1148                         m = gcm;
    1149                         while( m )
    1150                         {
     1138                        for( m = gcm; m; m = m->next )
    11511139                                if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 )
    1152                                         return( imc_away_alias_list[i][j] );
    1153                                 m = m->next;
    1154                         }
    1155                 }
    1156         }
    1157        
    1158         return( NULL );
     1140                                {
     1141                                        if( !keep_message )
     1142                                                *message = NULL;
     1143                                       
     1144                                        return imc_away_alias_list[i][j];
     1145                                }
     1146                }
     1147               
     1148                /* No need to look further, apparently this state doesn't
     1149                   have any good alias for this protocol. */
     1150                break;
     1151        }
     1152       
     1153        return NULL;
    11591154}
    11601155
Note: See TracChangeset for help on using the changeset viewer.