static void add_substatus(EditStatus *edit, PurpleAccount *account) { char *name; const char *type = NULL, *message = NULL; PurpleSavedStatusSub *sub = NULL; RowInfo *key; if (!edit || !edit->tree) return; if (edit->saved) sub = purple_savedstatus_get_substatus(edit->saved, account); key = g_new0(RowInfo, 1); key->account = account; if (sub) { key->type = purple_savedstatus_substatus_get_type(sub); type = purple_status_type_get_name(key->type); message = purple_savedstatus_substatus_get_message(sub); key->message = g_strdup(message); } name = g_strdup_printf("%s (%s)", purple_account_get_username(account), purple_account_get_protocol_name(account)); gnt_tree_add_choice(GNT_TREE(edit->tree), key, gnt_tree_create_row(GNT_TREE(edit->tree), name, type ? type : "", message ? message : ""), NULL, NULL); if (sub) gnt_tree_set_choice(GNT_TREE(edit->tree), key, TRUE); g_free(name); }
//gets the text of whatever the user sets the status to. (not necessarily what status is on the server) //client_text and server_text are freed if it returns false static gboolean getStatusText(char** client_text, char** server_text, PurpleAccount *account, const char** sid) { PurpleStatus* status; PurpleSavedStatus* savedStatus; PurpleSavedStatusSub* substat; const char* statusMessage; status = purple_account_get_active_status(account); if (status == NULL) { purple_debug_fatal("MusicInfo", "Account with NULL status\n"); return FALSE; } *sid = purple_status_get_id(status); statusMessage = purple_status_get_attr_string(status, "message"); if(statusMessage != NULL) { *server_text = g_strdup(statusMessage); } else { *server_text = g_strdup("\0"); } savedStatus = purple_savedstatus_get_current(); if (savedStatus == NULL) { purple_debug_fatal("MusicInfo", "Account with NULL saved status\n"); g_free(*server_text); return FALSE; } statusMessage = NULL; if(purple_savedstatus_has_substatuses(savedStatus)) { substat = purple_savedstatus_get_substatus(savedStatus, account); if(substat != NULL) statusMessage = purple_savedstatus_substatus_get_message(substat); } if(statusMessage == NULL) { statusMessage = purple_savedstatus_get_message(savedStatus); } if(statusMessage == NULL) { g_free(*server_text); return FALSE; } *client_text = g_strdup(statusMessage); return TRUE; }
static gboolean set_status (PurpleAccount *acnt, const char *loc) { // discover the pidgin saved status in use for this account const char *savedmessage = ""; { PurpleSavedStatus *savedstatus = purple_savedstatus_get_current(); if (savedstatus) { PurpleSavedStatusSub *savedsubstatus = purple_savedstatus_get_substatus(savedstatus, acnt); if (savedsubstatus) { // use account-specific saved status savedmessage = purple_savedstatus_substatus_get_message(savedsubstatus); } else { // don't have an account-specific saved status, use the general one savedmessage = purple_savedstatus_get_message(savedstatus); } } } /* generate status */ char *msg; if (savedmessage) { msg = (char *)malloc(strlen(savedmessage)+strlen(loc)+1); strcpy(msg, loc); strcat(msg, savedmessage); } else msg = loc; PurpleStatus *status = purple_account_get_active_status (acnt); GList *attrs = NULL; attrs = g_list_append(attrs, "message"); attrs = g_list_append(attrs, (gpointer)msg); purple_status_set_active_with_attrs_list(status, TRUE, attrs); g_list_free(attrs); trace("setup the account(%s) status: %s", acnt->username, msg); if (savedmessage) { free(msg); } return TRUE; }
static gboolean popup_substatus(GntTree *tree, const char *key, EditStatus *edit) { if (key[0] == ' ' && key[1] == 0) { EditSubStatus *sub; GntWidget *window, *combo, *entry, *box, *button, *l; PurpleSavedStatusSub *substatus = NULL; GList *iter; char *name; RowInfo *selected = gnt_tree_get_selection_data(tree); PurpleAccount *account = selected->account; if (gnt_tree_get_choice(tree, selected)) { /* There was a savedstatus for this account. Now remove it. */ g_free(selected->message); selected->type = NULL; selected->message = NULL; /* XXX: should we really be saving it right now? */ purple_savedstatus_unset_substatus(edit->saved, account); gnt_tree_change_text(tree, account, 1, NULL); gnt_tree_change_text(tree, account, 2, NULL); return FALSE; } if (g_hash_table_lookup(edit->hash, account)) return TRUE; if (edit->saved) substatus = purple_savedstatus_get_substatus(edit->saved, account); sub = g_new0(EditSubStatus, 1); sub->parent = edit; sub->key = selected; sub->window = window = gnt_vbox_new(FALSE); gnt_box_set_toplevel(GNT_BOX(window), TRUE); gnt_box_set_title(GNT_BOX(window), _("Substatus")); /* XXX: a better title */ gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); box = gnt_hbox_new(FALSE); gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Account:"))); name = g_strdup_printf("%s (%s)", purple_account_get_username(account), purple_account_get_protocol_name(account)); gnt_box_add_widget(GNT_BOX(box), gnt_label_new(name)); g_free(name); gnt_box_add_widget(GNT_BOX(window), box); box = gnt_hbox_new(FALSE); gnt_box_add_widget(GNT_BOX(box), (l = gnt_label_new(_("Status:")))); gnt_widget_set_size(l, 0, 1); /* I don't like having to do this */ sub->type = combo = gnt_combo_box_new(); gnt_box_add_widget(GNT_BOX(box), combo); gnt_box_add_widget(GNT_BOX(window), box); for (iter = purple_account_get_status_types(account); iter; iter = iter->next) { PurpleStatusType *type = iter->data; if (!purple_status_type_is_user_settable(type)) continue; gnt_combo_box_add_data(GNT_COMBO_BOX(combo), type, purple_status_type_get_name(type)); } box = gnt_hbox_new(FALSE); gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message:"))); sub->message = entry = gnt_entry_new(substatus ? purple_savedstatus_substatus_get_message(substatus) : NULL); gnt_box_add_widget(GNT_BOX(box), entry); gnt_box_add_widget(GNT_BOX(window), box); box = gnt_hbox_new(FALSE); button = gnt_button_new(_("Cancel")); g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); gnt_box_add_widget(GNT_BOX(box), button); button = gnt_button_new(_("Save")); g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_substatus_cb), sub); gnt_box_add_widget(GNT_BOX(box), button); gnt_box_add_widget(GNT_BOX(window), box); gnt_widget_show(window); g_hash_table_insert(edit->hash, account, sub); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(substatus_window_destroy_cb), sub); return TRUE; } return FALSE; }