From ba3d68c50765c29fc4e25c99a761903f2a143993 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Tue, 7 Feb 2017 19:03:05 +0100 Subject: [PATCH] Added function to clear the listStore --- src/main.c | 3 +++ src/mainwindow.c | 2 +- src/mdiary.c | 34 ++++++++++++++++++++++++++++++++++ src/mdiary.h | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index d358c17..46fdfc4 100644 --- a/src/main.c +++ b/src/main.c @@ -16,6 +16,9 @@ int main(int argc, char *argv[]) mdiary_scan_to_store(argv[1], mainWindow->entryListStore, mainWindow->completionListStore); mainWindow_set_meta_information(mainWindow, mdiary_get_time_earliest(), mdiary_get_time_latest(), FALSE); + mainWindow_set_meta_information(mainWindow, mdiary_get_time_earliest(), mdiary_get_time_latest(), TRUE); + mdiary_reset_store(mainWindow->entryListStore, mainWindow->completionListStore); + gtk_main(); return 0; diff --git a/src/mainwindow.c b/src/mainwindow.c index a610bec..e70a5cc 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -475,7 +475,7 @@ void mainWindow_set_meta_information(struct mainWindow *mainWindow, mainWindow->time_earliest = time_earliest; mainWindow->time_latest = time_latest; mainWindow->filterSettings.hide_all = hide_all; - + gtk_widget_set_sensitive(mainWindow->mainPane, !hide_all); mainWindow_clearSearch(NULL, mainWindow); } diff --git a/src/mdiary.c b/src/mdiary.c index 3411369..560fa3e 100644 --- a/src/mdiary.c +++ b/src/mdiary.c @@ -500,3 +500,37 @@ void mdiary_add_entry_to_store(GtkListStore *entryListStore, -1); } } + +/** + * @brief mdiary_free_entry_elements frees all non-GtkListView-managed parts of the mdiary entry + * @param model + * @param path + * @param iter + * @param data + * @return FALSE + */ +gboolean mdiary_free_entry_elements(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { + gpointer ptr; + + gtk_tree_model_get(model, iter, COL_TAGLIST, &ptr, -1); + g_list_free_full((GList *)ptr, g_free); + + gtk_tree_model_get(model, iter, COL_TIMESTAMP, &ptr, -1); + g_date_time_unref((GDateTime *)ptr); + + return FALSE; +} + +/** + * @brief mdiary_reset_store clears the two GtkListStores and frees all of their respective elements. (Make sure that + * no other part of the program tries to access the elements of the store while executing this function.) + * @param entryListStore + * @param autoCompletion + */ +void mdiary_reset_store(GtkListStore *entryListStore, GtkListStore *autoCompletion) +{ + + gtk_tree_model_foreach(GTK_TREE_MODEL(entryListStore), mdiary_free_entry_elements, NULL); + gtk_list_store_clear(entryListStore); + gtk_list_store_clear(autoCompletion); +} diff --git a/src/mdiary.h b/src/mdiary.h index 944e5b5..23fdd25 100644 --- a/src/mdiary.h +++ b/src/mdiary.h @@ -28,5 +28,6 @@ GDateTime *mdiary_get_date_from_string_ext(gchar *string, gchar *prefix, gchar * GDateTime *mdiary_get_date_from_string(gchar *string); gint64 mdiary_get_time_earliest(void); gint64 mdiary_get_time_latest(void); +void mdiary_reset_store(GtkListStore *entryListStore, GtkListStore *autoCompletion); #endif /* MDIARY_H */