Changeset fc650a8


Ignore:
Timestamp:
2015-03-15T09:29:01Z (9 years ago)
Author:
dequis <dx@…>
Children:
c0e4c22
Parents:
89db90e (diff), 2dd23da (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:

Merge branch 'develop' into feat/hip-cat

Location:
protocols
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/bpurple.h

    r89db90e rfc650a8  
    55#include <glib.h>
    66
     7#define PURPLE_REQUEST_HANDLE "purple_request"
     8
    79struct purple_data
    810{
    911    PurpleAccount *account;
     12
     13    GHashTable *input_requests;
     14    guint next_request_id;
    1015};
    1116
  • protocols/purple/purple.c

    r89db90e rfc650a8  
    4040static char *set_eval_display_name(set_t *set, char *value);
    4141
     42void purple_request_input_callback(guint id, struct im_connection *ic,
     43                                   const char *message, const char *who);
     44
     45/* purple_request_input specific stuff */
     46typedef void (*ri_callback_t)(gpointer, const gchar *);
     47
     48struct request_input_data {
     49        ri_callback_t data_callback;
     50        void *user_data;
     51        struct im_connection *ic;
     52        char *buddy;
     53        guint id;
     54};
     55
    4256struct im_connection *purple_ic_by_pa(PurpleAccount *pa)
    4357{
     
    311325        ic->proto_data = pd = g_new0(struct purple_data, 1);
    312326        pd->account = purple_account_new(acc->user, (char *) acc->prpl->data);
     327        pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal,
     328                                                   NULL, g_free);
     329        pd->next_request_id = 0;
    313330        purple_account_set_password(pd->account, acc->pass);
    314331        purple_sync_settings(acc, pd->account);
     
    320337{
    321338        struct purple_data *pd = ic->proto_data;
     339
     340        if (!pd) {
     341                return;
     342        }
    322343
    323344        purple_account_set_enabled(pd->account, "BitlBee", FALSE);
    324345        purple_connections = g_slist_remove(purple_connections, ic);
    325346        purple_accounts_remove(pd->account);
     347        g_hash_table_destroy(pd->input_requests);
    326348        g_free(pd);
    327349}
     
    331353        PurpleConversation *conv;
    332354        struct purple_data *pd = ic->proto_data;
     355
     356        if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) {
     357                guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE));
     358                purple_request_input_callback(request_id, ic, message, who);
     359                return 1;
     360        }
    333361
    334362        if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
     
    9961024                pqad->yes(pqad->user_data, pqad->yes_i);
    9971025        }
    998         g_free(pqad);
    9991026}
    10001027
     
    10061033                pqad->no(pqad->user_data, pqad->no_i);
    10071034        }
    1008         g_free(pqad);
     1035}
     1036
     1037/* q->free() callback from query_del()*/
     1038static void prplcb_request_action_free(void *data)
     1039{
     1040        struct prplcb_request_action_data *pqad = data;
     1041
     1042        pqad->bee_data = NULL;
     1043        purple_request_close(PURPLE_REQUEST_ACTION, pqad);
    10091044}
    10101045
     
    10411076        q = g_strdup_printf("Request: %s\n\n%s\n\n%s", title, primary, secondary);
    10421077        pqad->bee_data = query_add(local_bee->ui_data, purple_ic_by_pa(account), q,
    1043                                    prplcb_request_action_yes, prplcb_request_action_no, g_free, pqad);
     1078                                   prplcb_request_action_yes, prplcb_request_action_no,
     1079                                   prplcb_request_action_free, pqad);
    10441080
    10451081        g_free(q);
     
    10541090static void prplcb_close_request(PurpleRequestType type, void *data)
    10551091{
    1056         if (type == PURPLE_REQUEST_ACTION) {
    1057                 struct prplcb_request_action_data *pqad = data;
    1058                 query_del(local_bee->ui_data, pqad->bee_data);
    1059         }
    1060         /* Add the request input handler here when that becomes a thing */
    1061 }
    1062 
    1063 /*
    1064 static void prplcb_request_test()
    1065 {
    1066         fprintf( stderr, "bla\n" );
    1067 }
    1068 */
     1092        struct prplcb_request_action_data *pqad;
     1093        struct request_input_data *ri;
     1094        struct purple_data *pd;
     1095
     1096        if (!data) {
     1097                return;
     1098        }
     1099
     1100        switch (type) {
     1101        case PURPLE_REQUEST_ACTION:
     1102                pqad = data;
     1103                /* if this is null, it's because query_del was run already */
     1104                if (pqad->bee_data) {
     1105                        query_del(local_bee->ui_data, pqad->bee_data);
     1106                }
     1107                g_free(pqad);
     1108                break;
     1109        case PURPLE_REQUEST_INPUT:
     1110                ri = data;
     1111                pd = ri->ic->proto_data;
     1112                imcb_remove_buddy(ri->ic, ri->buddy, NULL);
     1113                g_free(ri->buddy);
     1114                g_hash_table_remove(pd->input_requests, GUINT_TO_POINTER(ri->id));
     1115                break;
     1116        default:
     1117                g_free(data);
     1118                break;
     1119        }
     1120
     1121}
     1122
     1123void* prplcb_request_input(const char *title, const char *primary,
     1124        const char *secondary, const char *default_value, gboolean multiline,
     1125        gboolean masked, gchar *hint, const char *ok_text, GCallback ok_cb,
     1126        const char *cancel_text, GCallback cancel_cb, PurpleAccount *account,
     1127        const char *who, PurpleConversation *conv, void *user_data)
     1128{
     1129        struct im_connection *ic = purple_ic_by_pa(account);
     1130        struct purple_data *pd = ic->proto_data;
     1131        struct request_input_data *ri = g_new0(struct request_input_data, 1);
     1132        guint id = pd->next_request_id++;
     1133
     1134        ri->id = id;
     1135        ri->ic = ic;
     1136        ri->buddy = g_strdup_printf("%s_%u", PURPLE_REQUEST_HANDLE, id);
     1137        ri->data_callback = (ri_callback_t) ok_cb;
     1138        ri->user_data = user_data;
     1139        g_hash_table_insert(pd->input_requests, GUINT_TO_POINTER(id), ri);
     1140
     1141        imcb_add_buddy(ic, ri->buddy, NULL);
     1142        imcb_buddy_msg(ic, ri->buddy, secondary, 0, 0);
     1143
     1144        return ri;
     1145}
     1146
     1147void purple_request_input_callback(guint id, struct im_connection *ic,
     1148                                   const char *message, const char *who)
     1149{
     1150        struct purple_data *pd = ic->proto_data;
     1151        struct request_input_data *ri;
     1152
     1153        if (!(ri = g_hash_table_lookup(pd->input_requests, GUINT_TO_POINTER(id)))) {
     1154                return;
     1155        }
     1156
     1157        ri->data_callback(ri->user_data, message);
     1158
     1159        purple_request_close(PURPLE_REQUEST_INPUT, ri);
     1160}
     1161
    10691162
    10701163static PurpleRequestUiOps bee_request_uiops =
    10711164{
    1072         NULL,
     1165        prplcb_request_input,
    10731166        NULL,
    10741167        prplcb_request_action,
  • protocols/twitter/twitter_lib.c

    r89db90e rfc650a8  
    832832
    833833        last_id_str = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id);
    834         set_setstr(&ic->acc->set, "last_tweet", last_id_str);
     834        set_setstr(&ic->acc->set, "_last_tweet", last_id_str);
    835835        g_free(last_id_str);
    836836}
Note: See TracChangeset for help on using the changeset viewer.