/pidgin/main: 7847eb4b93b0: Make datasheet refresh easier with m...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Tue Jan 7 12:53:20 EST 2014
Changeset: 7847eb4b93b0c0187423f46a07e06ed68b8f0201
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-01-07 18:53 +0100
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/7847eb4b93b0
Description:
Make datasheet refresh easier with marking for removal routines
diffstat:
libpurple/request-datasheet.c | 46 ++++++++++++++++++++++++++++++++++++++++++-
libpurple/request-datasheet.h | 21 +++++++++++++++++++
2 files changed, 66 insertions(+), 1 deletions(-)
diffs (109 lines):
diff --git a/libpurple/request-datasheet.c b/libpurple/request-datasheet.c
--- a/libpurple/request-datasheet.c
+++ b/libpurple/request-datasheet.c
@@ -38,6 +38,8 @@ struct _PurpleRequestDatasheet
GList *record_list;
GHashTable *record_li_by_key;
+
+ GHashTable *marked_for_rem;
};
struct _PurpleRequestDatasheetRecord
@@ -112,6 +114,9 @@ purple_request_datasheet_free(PurpleRequ
g_list_free_full(sheet->record_list,
(GDestroyNotify)purple_request_datasheet_record_free);
+ if (sheet->marked_for_rem != NULL)
+ g_hash_table_destroy(sheet->marked_for_rem);
+
g_free(sheet);
}
@@ -333,8 +338,10 @@ purple_request_datasheet_record_add(Purp
g_return_val_if_fail(sheet != NULL, NULL);
rec = purple_request_datasheet_record_find(sheet, key);
- if (rec != NULL)
+ if (rec != NULL) {
+ g_hash_table_remove(sheet->marked_for_rem, key);
return rec;
+ }
rec = purple_request_datasheet_record_new();
rec->sheet = sheet;
@@ -386,6 +393,43 @@ purple_request_datasheet_record_remove_a
purple_signal_emit(sheet, "record-changed", sheet, NULL);
}
+void
+purple_request_datasheet_record_mark_all_for_rem(PurpleRequestDatasheet *sheet)
+{
+ const GList *it;
+
+ if (sheet->marked_for_rem != NULL)
+ g_hash_table_destroy(sheet->marked_for_rem);
+ sheet->marked_for_rem = g_hash_table_new(g_direct_hash, g_direct_equal);
+
+ it = purple_request_datasheet_get_records(sheet);
+ for (; it != NULL; it = g_list_next(it)) {
+ PurpleRequestDatasheetRecord *rec = it->data;
+ gpointer key = purple_request_datasheet_record_get_key(rec);
+
+ g_hash_table_insert(sheet->marked_for_rem, key, key);
+ }
+}
+
+void
+purple_request_datasheet_record_remove_marked(PurpleRequestDatasheet *sheet)
+{
+ GHashTableIter it;
+ gpointer key;
+ GHashTable *rem;
+
+ if (sheet->marked_for_rem == NULL)
+ return;
+ rem = sheet->marked_for_rem;
+ sheet->marked_for_rem = NULL;
+
+ g_hash_table_iter_init(&it, rem);
+ while (g_hash_table_iter_next(&it, &key, NULL))
+ purple_request_datasheet_record_remove(sheet, key);
+
+ g_hash_table_destroy(rem);
+}
+
static void
purple_request_datasheet_record_set_common_data(
PurpleRequestDatasheetRecord *rec, guint col_no, const gchar *data)
diff --git a/libpurple/request-datasheet.h b/libpurple/request-datasheet.h
--- a/libpurple/request-datasheet.h
+++ b/libpurple/request-datasheet.h
@@ -314,6 +314,27 @@ void
purple_request_datasheet_record_remove_all(PurpleRequestDatasheet *sheet);
/**
+ * Marks all records for removal. Record will be unmarked, when touched with
+ * purple_request_datasheet_record_add.
+ *
+ * @param sheet The datasheet.
+ *
+ * @see purple_request_datasheet_record_add.
+ */
+void
+purple_request_datasheet_record_mark_all_for_rem(PurpleRequestDatasheet *sheet);
+
+/**
+ * Removes all marked records.
+ *
+ * @param sheet The datasheet.
+ *
+ * @see purple_request_datasheet_record_mark_all_for_rem.
+ */
+void
+purple_request_datasheet_record_remove_marked(PurpleRequestDatasheet *sheet);
+
+/**
* Sets data for a string column of specified record.
*
* @param rec The record.
More information about the Commits
mailing list