summaryrefslogtreecommitdiff
path: root/window_tag.c
diff options
context:
space:
mode:
Diffstat (limited to 'window_tag.c')
-rw-r--r--window_tag.c69
1 files changed, 18 insertions, 51 deletions
diff --git a/window_tag.c b/window_tag.c
index 52db1ad..6a067dc 100644
--- a/window_tag.c
+++ b/window_tag.c
@@ -26,79 +26,40 @@ void on_tagview_cell_toggled(GtkCellRendererToggle *cell_renderer, gchar *path_s
}
}
-/* TODO: Find a better way to do this. */
-inline static gboolean is_tag_inconsistent(struct tag_t *tag, GArray *walltags, gboolean *exists) {
- gint n_y, n_n;
- GArray *walltag_single;
- gboolean found;
- struct tag_t *wall_tag;
-
- n_y = n_n = 0;
-
- for(int i = 0; i < walltags->len; i++) {
- walltag_single = g_array_index(walltags, GArray*, i);
- found = FALSE;
- for(int j = 0; j < walltag_single->len; j++) {
- wall_tag = &g_array_index(walltag_single, struct tag_t, j);
- if(wall_tag->id == tag->id) {
- n_y++;
- found = TRUE;
- break;
- }
- }
- if(!found)
- n_n++;
- }
- if(n_y == 0)
- *exists = FALSE;
- else
- *exists = TRUE;
- return (n_n == 0 || n_y == 0 ? FALSE : TRUE);
-}
-
/**
* foreach-callback for setting checked and inconsistent in the tag model.
*/
static gboolean tagview_model_foreach(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) {
struct tag_t *tag;
- gboolean inconsistent, exists;
+ struct tagdialog_data_t *data;
+ struct tag_inconsistent_data_t *inconsistent_data;
+
+ data = user_data;
tag_model_get_tag_record(GTK_TREE_MODEL(model), iter, &tag);
- inconsistent = is_tag_inconsistent(tag, (GArray*)user_data, &exists);
- tag_model_set_checked(GTK_TREE_MODEL(model), iter, exists);
- tag_model_set_inconsistent(GTK_TREE_MODEL(model), iter, inconsistent);
+ inconsistent_data = g_hash_table_lookup(data->inconsistent_table, tag->id);
+ if(inconsistent_data) {
+ tag_model_set_checked(GTK_TREE_MODEL(model), iter, inconsistent_data->active);
+ tag_model_set_inconsistent(GTK_TREE_MODEL(model), iter, inconsistent_data->inconsistent);
+ }
return FALSE;
}
static void tagview_create_model(GtkTreeView *tagview, gpointer user_data) {
GtkTreeModel *model;
- GArray *walltags, *walltag_single, *wallarray;
+ GArray *wallarray;
struct tagdialog_data_t *data;
data = user_data;
wallarray = data->wallarray;
- walltags = g_array_new(FALSE, FALSE, sizeof(GArray*));
- for(int i = 0; i < wallarray->len; i++) {
- if(db_get_wall_tags(g_array_index(wallarray, guint64, i), &walltag_single)) {
- g_array_append_val(walltags, walltag_single);
- } else {
- g_error("db_get_wall_tags failed\n");
- return;
- }
- }
+ db_wall_tags_inconsistent(wallarray, &(data->inconsistent_table));
model = GTK_TREE_MODEL(tag_model_new());
gtk_tree_view_set_model(tagview, GTK_TREE_MODEL(model));
- gtk_tree_model_foreach(GTK_TREE_MODEL(model), tagview_model_foreach, walltags);
-
- for(int i = 0; i < walltags->len; i++) {
- walltag_single = g_array_index(walltags, GArray*, i);
- g_array_free(walltag_single, TRUE);
- }
- g_array_free(walltags, TRUE);
+ gtk_tree_model_foreach(GTK_TREE_MODEL(model), tagview_model_foreach, user_data);
gtk_tree_view_expand_all(tagview);
}
@@ -228,6 +189,11 @@ void on_tags_selnonebtn_clicked(GtkButton *button, gpointer user_data) {
}
void on_tagsdialog_destroy(GtkObject *object, gpointer user_data) {
+ struct tagdialog_data_t *data;
+
+ data = user_data;
+
+ g_hash_table_destroy(data->inconsistent_table);
g_free(user_data);
}
@@ -263,6 +229,7 @@ struct tagdialog_data_t *window_tagview_new(GtkWidget *parent, GArray* array) {
data->dialog = GTK_WIDGET(dialog);
data->tagview = GTK_WIDGET(tagview);
data->wallarray = array;
+ data->inconsistent_table = NULL;
tagview_init(tagview, data);