diff options
author | Gary Kramlich <grim@reaperworld.com> | 2019-10-15 04:05:27 +0000 |
---|---|---|
committer | Gary Kramlich <grim@reaperworld.com> | 2019-10-15 04:05:27 +0000 |
commit | e01b8bf7a7d0d57884757cf90b6f5461324966af (patch) | |
tree | d2adb8bd4e5be651de27029d95b6c488b738812f | |
parent | 39b76a242c23a5650cf0c4841441c19c7c6be684 (diff) | |
parent | 99fa3f497d3647eaca69bc0f14f426af3915f946 (diff) | |
download | pidgin-e01b8bf7a7d0d57884757cf90b6f5461324966af.tar.gz |
Merged in default (pull request #604)
Use GList functions instead of manual iterations
Approved-by: Elliott Sales de Andrade
Approved-by: Gary Kramlich
Approved-by: Eion Robb
-rw-r--r-- | finch/plugins/gnttinyurl.c | 20 | ||||
-rw-r--r-- | libpurple/e2ee.c | 3 | ||||
-rw-r--r-- | libpurple/media/backend-fs2.c | 5 | ||||
-rw-r--r-- | libpurple/plugins/idle.c | 9 | ||||
-rw-r--r-- | libpurple/protocols/bonjour/bonjour.c | 8 | ||||
-rw-r--r-- | libpurple/protocols/irc/msgs.c | 7 | ||||
-rw-r--r-- | libpurple/protocols/jabber/adhoccommands.c | 7 | ||||
-rw-r--r-- | libpurple/protocols/jabber/xdata.c | 19 | ||||
-rw-r--r-- | libpurple/protocols/zephyr/zephyr.c | 26 | ||||
-rw-r--r-- | libpurple/savedstatuses.c | 9 | ||||
-rw-r--r-- | pidgin/gtkaccount.c | 15 | ||||
-rw-r--r-- | pidgin/gtknotify.c | 18 | ||||
-rw-r--r-- | pidgin/plugins/screencap.c | 10 | ||||
-rw-r--r-- | pidgin/plugins/xmppconsole/xmppconsole.c | 15 |
14 files changed, 45 insertions, 126 deletions
diff --git a/finch/plugins/gnttinyurl.c b/finch/plugins/gnttinyurl.c index 4d82aab23d..6c04b77ed1 100644 --- a/finch/plugins/gnttinyurl.c +++ b/finch/plugins/gnttinyurl.c @@ -221,17 +221,15 @@ url_fetched(G_GNUC_UNUSED SoupSession *session, SoupMessage *msg, } /* ensure the conversation still exists */ - for (; convs; convs = convs->next) { - if ((PurpleConversation *)(convs->data) == conv) { - FinchConv *fconv = FINCH_CONV(conv); - gchar *str = g_strdup_printf("[%d] %s", data->num, url); - GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); - gnt_text_view_tag_change(tv, data->tag, str, FALSE); - g_free(str); - g_free(data->tag); - g_free(data); - return; - } + if (g_list_find(convs, conv)) { + FinchConv *fconv = FINCH_CONV(conv); + gchar *str = g_strdup_printf("[%d] %s", data->num, url); + GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); + gnt_text_view_tag_change(tv, data->tag, str, FALSE); + g_free(str); + g_free(data->tag); + g_free(data); + return; } g_free(data->tag); g_free(data); diff --git a/libpurple/e2ee.c b/libpurple/e2ee.c index 93568c545a..ed9aef3e56 100644 --- a/libpurple/e2ee.c +++ b/libpurple/e2ee.c @@ -189,8 +189,7 @@ purple_e2ee_provider_unregister(PurpleE2eeProvider *provider) main_provider = NULL; - for (it = clear_states; it; it = g_list_next(it)) - purple_conversation_set_e2ee_state(it->data, NULL); + g_list_foreach(clear_states, (GFunc)purple_conversation_set_e2ee_state, NULL); g_list_free(clear_states); } diff --git a/libpurple/media/backend-fs2.c b/libpurple/media/backend-fs2.c index 5237d96e90..8e28b42213 100644 --- a/libpurple/media/backend-fs2.c +++ b/libpurple/media/backend-fs2.c @@ -498,10 +498,7 @@ purple_media_backend_fs2_class_init(PurpleMediaBackendFs2Class *klass) /* VA-API elements aren't well supported in Farstream. Ignore them. */ features = gst_registry_get_feature_list_by_plugin(gst_registry_get(), "vaapi"); - for (it = features; it; it = it->next) { - gst_plugin_feature_set_rank((GstPluginFeature *)it->data, - GST_RANK_NONE); - } + g_list_foreach(features, (GFunc)gst_plugin_feature_set_rank, GINT_TO_POINTER(GST_RANK_NONE)); gst_plugin_feature_list_free(features); } diff --git a/libpurple/plugins/idle.c b/libpurple/plugins/idle.c index 649f3d828c..894aa5af2f 100644 --- a/libpurple/plugins/idle.c +++ b/libpurple/plugins/idle.c @@ -221,16 +221,9 @@ idle_all_action(PurplePluginAction *action) static void unidle_all_action(PurplePluginAction *action) { - GList *l; - /* freeing the list here will cause segfaults if the user idles an account * after the list is freed */ - for (l = idled_accts; l; l = l->next) - { - PurpleAccount *account = l->data; - set_idle_time(account, 0); - } - + g_list_foreach(idled_accts, (GFunc)set_idle_time, GINT_TO_POINTER(0)); g_list_free(idled_accts); idled_accts = NULL; } diff --git a/libpurple/protocols/bonjour/bonjour.c b/libpurple/protocols/bonjour/bonjour.c index 175592647c..1e4240cc45 100644 --- a/libpurple/protocols/bonjour/bonjour.c +++ b/libpurple/protocols/bonjour/bonjour.c @@ -444,17 +444,11 @@ bonjour_group_buddy(PurpleConnection *connection, const char *who, const char *o static void bonjour_rename_group(PurpleConnection *connection, const char *old_name, PurpleGroup *group, GList *moved_buddies) { - GList *cur; const char *new_group; - PurpleBuddy *buddy; new_group = purple_group_get_name(group); - for (cur = moved_buddies; cur; cur = cur->next) { - buddy = cur->data; - bonjour_do_group_change(buddy, new_group); - } - + g_list_foreach(moved_buddies, (GFunc)bonjour_do_group_change, new_group); } static gboolean diff --git a/libpurple/protocols/irc/msgs.c b/libpurple/protocols/irc/msgs.c index ec5c23ffab..070fe7bd91 100644 --- a/libpurple/protocols/irc/msgs.c +++ b/libpurple/protocols/irc/msgs.c @@ -699,14 +699,9 @@ void irc_msg_names(struct irc_conn *irc, const char *name, const char *from, cha } if (users != NULL) { - GList *l; - purple_chat_conversation_add_users(PURPLE_CHAT_CONVERSATION(convo), users, NULL, flags, FALSE); - for (l = users; l != NULL; l = l->next) - g_free(l->data); - - g_list_free(users); + g_list_free_full(users, g_free); g_list_free(flags); } diff --git a/libpurple/protocols/jabber/adhoccommands.c b/libpurple/protocols/jabber/adhoccommands.c index fd25bbd0f7..06f7793878 100644 --- a/libpurple/protocols/jabber/adhoccommands.c +++ b/libpurple/protocols/jabber/adhoccommands.c @@ -113,7 +113,6 @@ static void jabber_adhoc_parse(JabberStream *js, const char *from, static void do_adhoc_action_cb(JabberStream *js, PurpleXmlNode *result, const char *actionhandle, gpointer user_data) { PurpleXmlNode *command; - GList *action; JabberAdHocActionInfo *actionInfo = user_data; JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); jabber_iq_set_callback(iq, jabber_adhoc_parse, NULL); @@ -134,11 +133,7 @@ static void do_adhoc_action_cb(JabberStream *js, PurpleXmlNode *result, const ch purple_xmlnode_insert_child(command,result); } - for(action = actionInfo->actionslist; action; action = g_list_next(action)) { - char *handle = action->data; - g_free(handle); - } - g_list_free(actionInfo->actionslist); + g_list_free_full(actionInfo->actionslist, g_free); g_free(actionInfo->sessionid); g_free(actionInfo->who); g_free(actionInfo->node); diff --git a/libpurple/protocols/jabber/xdata.c b/libpurple/protocols/jabber/xdata.c index 81b5448281..94bf0324c7 100644 --- a/libpurple/protocols/jabber/xdata.c +++ b/libpurple/protocols/jabber/xdata.c @@ -145,13 +145,7 @@ static void jabber_x_data_ok_cb(struct jabber_x_data_data *data, PurpleRequestFi g_free(data->values->data); data->values = g_slist_delete_link(data->values, data->values); } - if (data->actions) { - GList *action; - for(action = data->actions; action; action = g_list_next(action)) { - g_free(action->data); - } - g_list_free(data->actions); - } + g_list_free_full(data->actions, g_free); g_free(data); if (hasActions) @@ -167,20 +161,13 @@ static void jabber_x_data_cancel_cb(struct jabber_x_data_data *data, PurpleReque jabber_x_data_action_cb cb = data->cb; gpointer user_data = data->user_data; JabberStream *js = data->js; - gboolean hasActions = FALSE; + gboolean hasActions = (data->actions != NULL); g_hash_table_destroy(data->fields); while(data->values) { g_free(data->values->data); data->values = g_slist_delete_link(data->values, data->values); } - if (data->actions) { - GList *action; - hasActions = TRUE; - for(action = data->actions; action; action = g_list_next(action)) { - g_free(action->data); - } - g_list_free(data->actions); - } + g_list_free_full(data->actions, g_free); g_free(data); purple_xmlnode_set_namespace(result, "jabber:x:data"); diff --git a/libpurple/protocols/zephyr/zephyr.c b/libpurple/protocols/zephyr/zephyr.c index aff4315789..f756b61aea 100644 --- a/libpurple/protocols/zephyr/zephyr.c +++ b/libpurple/protocols/zephyr/zephyr.c @@ -740,16 +740,16 @@ static char *zephyr_to_html(const char *message) static gboolean pending_zloc(zephyr_account *zephyr, const char *who) { GList *curr; + char* normalized_who = local_zephyr_normalize(zephyr,who); - for (curr = zephyr->pending_zloc_names; curr != NULL; curr = curr->next) { - char* normalized_who = local_zephyr_normalize(zephyr,who); - if (!g_ascii_strcasecmp(normalized_who, (char *)curr->data)) { - g_free((char *)curr->data); - zephyr->pending_zloc_names = g_list_delete_link(zephyr->pending_zloc_names, curr); - return TRUE; - } - } - return FALSE; + curr = g_list_find_custom(zephyr->pending_zloc_names, normalized_who, (GCompareFunc)g_ascii_strcasecmp); + g_free(normalized_who); + if (curr == NULL) + return FALSE; + + g_free((char *)curr->data); + zephyr->pending_zloc_names = g_list_delete_link(zephyr->pending_zloc_names, curr); + return TRUE; } /* Called when the server notifies us a message couldn't get sent */ @@ -1982,17 +1982,11 @@ static void write_anyone(zephyr_account *zephyr) static void zephyr_close(PurpleConnection * gc) { - GList *l; GSList *s; zephyr_account *zephyr = purple_connection_get_protocol_data(gc); pid_t tzc_pid = zephyr->tzc_pid; - l = zephyr->pending_zloc_names; - while (l) { - g_free((char *)l->data); - l = l->next; - } - g_list_free(zephyr->pending_zloc_names); + g_list_free_full(zephyr->pending_zloc_names, g_free); if (purple_account_get_bool(purple_connection_get_account(gc), "write_anyone", FALSE)) write_anyone(zephyr); diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c index a54206b31c..acfd59b2d2 100644 --- a/libpurple/savedstatuses.c +++ b/libpurple/savedstatuses.c @@ -683,16 +683,9 @@ static void purple_savedstatus_unset_all_substatuses(const PurpleAccount *account, gpointer user_data) { - GList *iter; - PurpleSavedStatus *status; - g_return_if_fail(account != NULL); - for (iter = saved_statuses; iter != NULL; iter = iter->next) - { - status = (PurpleSavedStatus *)iter->data; - purple_savedstatus_unset_substatus(status, account); - } + g_list_foreach(saved_statuses, (GFunc)purple_savedstatus_unset_substatus, account); } void diff --git a/pidgin/gtkaccount.c b/pidgin/gtkaccount.c index 7a7e2c9404..f685a4a58d 100644 --- a/pidgin/gtkaccount.c +++ b/pidgin/gtkaccount.c @@ -2208,7 +2208,6 @@ static gboolean populate_accounts_list(AccountsWindow *dialog) { GList *l; - gboolean ret = FALSE; GdkPixbuf *global_buddyicon = NULL; const char *path; @@ -2222,15 +2221,13 @@ populate_accounts_list(AccountsWindow *dialog) } } - for (l = purple_accounts_get_all(); l != NULL; l = l->next) { - ret = TRUE; - add_account_to_liststore((PurpleAccount *)l->data, global_buddyicon); - } + l = purple_accounts_get_all(); + g_list_foreach(l, (GFunc)add_account_to_liststore, global_buddyicon); if (global_buddyicon != NULL) g_object_unref(G_OBJECT(global_buddyicon)); - return ret; + return l != NULL; } static void @@ -2388,10 +2385,8 @@ static void global_buddyicon_changed(const char *name, PurplePrefType type, gconstpointer value, gpointer window) { - GList *list; - for (list = purple_accounts_get_all(); list; list = list->next) { - account_modified_cb(list->data, window); - } + GList *list = purple_accounts_get_all(); + g_list_foreach(list, (GFunc)account_modified_cb, window); } void diff --git a/pidgin/gtknotify.c b/pidgin/gtknotify.c index bb36f9cc8f..77be7a6433 100644 --- a/pidgin/gtknotify.c +++ b/pidgin/gtknotify.c @@ -274,7 +274,6 @@ pounce_response_edit_cb(GtkTreeModel *model, GtkTreePath *path, { PidginNotifyPounceData *pounce_data; PidginNotifyDialog *dialog = (PidginNotifyDialog*)data; - PurplePounce *pounce; GList *list; list = purple_pounces_get_all(); @@ -283,12 +282,9 @@ pounce_response_edit_cb(GtkTreeModel *model, GtkTreePath *path, PIDGIN_POUNCE_DATA, &pounce_data, -1); - for (; list != NULL; list = list->next) { - pounce = list->data; - if (pounce == pounce_data->pounce) { - pidgin_pounce_editor_show(pounce_data->account, NULL, pounce_data->pounce); - return; - } + if (g_list_find(list, pounce_data->pounce) != NULL) { + pidgin_pounce_editor_show(pounce_data->account, NULL, pounce_data->pounce); + return; } purple_debug_warning("gtknotify", "Pounce was destroyed.\n"); @@ -348,12 +344,8 @@ pounce_row_selected_cb(GtkTreeView *tv, GtkTreePath *path, g_list_free_full(list, (GDestroyNotify)gtk_tree_path_free); pounces = purple_pounces_get_all(); - for (; pounces != NULL; pounces = pounces->next) { - PurplePounce *pounce = pounces->data; - if (pounce == pounce_data->pounce) { - gtk_widget_set_sensitive(pounce_dialog->edit_button, TRUE); - break; - } + if (g_list_find(pounces, pounce_data->pounce) != NULL) { + gtk_widget_set_sensitive(pounce_dialog->edit_button, TRUE); } gtk_widget_set_sensitive(pounce_dialog->open_button, TRUE); diff --git a/pidgin/plugins/screencap.c b/pidgin/plugins/screencap.c index 8f1f5840a5..c8d4ad900f 100644 --- a/pidgin/plugins/screencap.c +++ b/pidgin/plugins/screencap.c @@ -720,14 +720,10 @@ scrncap_convwin_init(PidginConvWindow *win) g_return_if_fail(conv_insert_image != NULL); conv_submenu = gtk_widget_get_parent(conv_insert_image); - pos = -1; children = gtk_container_get_children(GTK_CONTAINER(conv_submenu)); - for (it = children, i = 0; it; it = g_list_next(it), i++) { - if (it->data == conv_insert_image) { - pos = i + 1; - break; - } - } + pos = g_list_index(children, conv_insert_image); + if (pos != -1) + ++pos; g_list_free(children); g_warn_if_fail(pos >= 0); diff --git a/pidgin/plugins/xmppconsole/xmppconsole.c b/pidgin/plugins/xmppconsole/xmppconsole.c index 449e778f8c..811e307e80 100644 --- a/pidgin/plugins/xmppconsole/xmppconsole.c +++ b/pidgin/plugins/xmppconsole/xmppconsole.c @@ -514,22 +514,13 @@ signing_on_cb(PurpleConnection *gc) static void signed_off_cb(PurpleConnection *gc) { - int i = 0; - GList *l; + int i; if (!console) return; - l = console->accounts; - while (l) { - PurpleConnection *g = l->data; - if (gc == g) - break; - i++; - l = l->next; - } - - if (l == NULL) + i = g_list_index(console->accounts, gc); + if (i == -1) return; gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(console->dropdown), i); |