Compare commits

...

2 Commits

Author SHA1 Message Date
686f828c81 Implemented other workspaces function 2017-02-07 19:53:51 +01:00
ba3d68c507 Added function to clear the listStore 2017-02-07 19:03:05 +01:00
6 changed files with 120 additions and 37 deletions

View File

@ -2,11 +2,6 @@
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkFileChooserWidget" id="chooseDirectoryDialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action">select-folder</property>
</object>
<object class="GtkTextBuffer" id="entryTextBuffer"/>
<object class="GtkPopover" id="popoverWorkspace">
<property name="can_focus">False</property>

View File

@ -13,9 +13,6 @@ int main(int argc, char *argv[])
mainWindow = mainWindow_new();
gtk_widget_show(mainWindow->mainWindow);
mdiary_scan_to_store(argv[1], mainWindow->entryListStore, mainWindow->completionListStore);
mainWindow_set_meta_information(mainWindow, mdiary_get_time_earliest(), mdiary_get_time_latest(), FALSE);
gtk_main();
return 0;

View File

@ -188,9 +188,9 @@ static void mainWindow_configure_workspaceTreeView(struct mainWindow *mainWindow
G_TYPE_STRING);
mainWindow->workspaceListFiltered = GTK_TREE_MODEL_FILTER(
gtk_tree_model_filter_new(
GTK_TREE_MODEL(mainWindow->workspaceListStore),
NULL));
gtk_tree_model_filter_new(
GTK_TREE_MODEL(mainWindow->workspaceListStore),
NULL));
gtk_tree_model_filter_set_visible_func(mainWindow->workspaceListFiltered,
(GtkTreeModelFilterVisibleFunc) mainWindow_workspace_entry_visible,
@ -431,9 +431,10 @@ struct mainWindow *mainWindow_new()
mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView"));
mainWindow->entryListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder, "entryListSelection"));
mainWindow->textBuffer = GTK_TEXT_BUFFER(gtk_builder_get_object(builder, "entryTextBuffer"));
mainWindow->searchEntryCompletion = GTK_ENTRY_COMPLETION(gtk_builder_get_object(builder,
"searchEntryCompletion"));
mainWindow->searchEntryCompletion = GTK_ENTRY_COMPLETION(gtk_builder_get_object(
builder, "searchEntryCompletion"));
mainWindow->chooseDirectoryDialog = GTK_FILE_CHOOSER_DIALOG(gtk_builder_get_object(
builder, "chooseDirectoryDialog"));
mainWindow->buttonOtherWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "buttonOtherWorkspace"));
mainWindow->workspaceSearch = GTK_WIDGET(gtk_builder_get_object(builder, "searchWorkspace"));
mainWindow->popoverWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "popoverWorkspace"));
@ -457,6 +458,7 @@ struct mainWindow *mainWindow_new()
mainWindow_init_to_default(mainWindow);
mainWindow_clearSearch(NULL, mainWindow);
mainWindow_configure_entry_completion(mainWindow);
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
return mainWindow;
}
@ -475,21 +477,10 @@ 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);
}
/**
* @brief mainWindow_otherWorkspaceClicked is called when the user clicks the Other Workspace button.
* @param widget N/A
* @param event N/A
* @param user_data struct mainWindow *
*/
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data)
{
g_print("TODO: Show directory browser dialog.\n");
}
/**
* @brief mainWindow_showPopover is called from a dateEntry when it is focused.
* @param widget is the text entry.
@ -611,13 +602,13 @@ void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data)
}
mainWindow->filterSettings.search_title = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(mainWindow->checkSearchTitle));
GTK_TOGGLE_BUTTON(mainWindow->checkSearchTitle));
mainWindow->filterSettings.search_tags = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(mainWindow->checkSearchTags));
GTK_TOGGLE_BUTTON(mainWindow->checkSearchTags));
mainWindow->filterSettings.search_text = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(mainWindow->checkSearchText));
GTK_TOGGLE_BUTTON(mainWindow->checkSearchText));
mainWindow->filterSettings.search_summary = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(mainWindow->checkSearchSummary));
GTK_TOGGLE_BUTTON(mainWindow->checkSearchSummary));
gtk_tree_model_filter_refilter(mainWindow->entryListFiltered);
}
@ -688,6 +679,35 @@ void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpoi
mainWindow_clearSearch(widget, user_data);
}
static void mainWindow_show_error(struct mainWindow *mainWindow, gchar *text)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new(GTK_WINDOW(mainWindow->mainWindow),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error: %s",
text);
gtk_dialog_run(GTK_DIALOG (dialog));
gtk_widget_destroy(dialog);
}
static void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path)
{
g_print("Switching workspace to %s.\n", path);
gtk_popover_popdown(GTK_POPOVER(mainWindow->popoverWorkspace));
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
mdiary_reset_store(mainWindow->entryListStore, mainWindow->completionListStore);
if (mdiary_scan_to_store(path, mainWindow->entryListStore, mainWindow->completionListStore))
mainWindow_set_meta_information(mainWindow,
mdiary_get_time_earliest(), mdiary_get_time_latest(),
FALSE);
else
mainWindow_show_error(mainWindow, "Could not open workspace or no entries were found in it.");
}
void mainWindow_workspaceListClicked(GtkWidget *widget,
GtkTreePath *tree_path,
GtkTreeViewColumn *column,
@ -704,7 +724,41 @@ void mainWindow_workspaceListClicked(GtkWidget *widget,
selection = gtk_tree_view_get_selection(mainWindow->workspaceListView);
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
gtk_tree_model_get(model, &iter, WSCOL_PATH, &path, -1);
g_print("TODO: Switch workspace to %s\n", path);
mainWindow_switch_workspace(mainWindow, path);
g_free(path);
}
}
/**
* @brief mainWindow_otherWorkspaceClicked is called when the user clicks the Other Workspace button.
* @param widget N/A
* @param event N/A
* @param user_data struct mainWindow *
*/
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gpointer user_data)
{
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
GtkWidget *dialog;
gint res;
dialog = gtk_file_chooser_dialog_new("Choose Workspace", GTK_WINDOW(mainWindow->mainWindow), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
"Cancel", GTK_RESPONSE_CANCEL,
"Select", GTK_RESPONSE_ACCEPT,
NULL);
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
res = gtk_dialog_run (GTK_DIALOG (dialog));
if (res == GTK_RESPONSE_ACCEPT) {
char *directory;
directory = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog));
mainWindow_switch_workspace(mainWindow, directory);
g_free (directory);
}
gtk_widget_destroy (dialog);
g_print("TODO: Show directory browser dialog.\n");
}

View File

@ -21,6 +21,7 @@ struct mainWindow {
GtkWidget *checkSearchText;
GtkWidget *labelSummary;
GtkWidget *buttonClearSearch;
GtkFileChooserWidget *chooseDirectoryDialog;
GtkTreeView *entryListView;
GtkTreeSelection *entryListSelection;
GtkTextBuffer *textBuffer;
@ -61,7 +62,7 @@ void mainWindow_set_meta_information(struct mainWindow *mainWindow,
/* Slots */
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data);
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data);
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gpointer user_data);
void mainWindow_workspaceListClicked(GtkWidget *widget,
GtkTreePath *tree_path,
GtkTreeViewColumn *column,

View File

@ -328,15 +328,14 @@ static void mdiary_recurse_and_collect(gchar *base_dir,
GtkListStore *autoCompletion,
guint max_level)
{
GError *error;
GDir *dir = g_dir_open(base_dir, 0, &error);
GDir *dir = g_dir_open(base_dir, 0, NULL);
gchar *dirname;
gchar *fullPath;
GRegex *regex;
GMatchInfo *match_info;
if (!dir) {
g_print("Error, could not open base directory.\n");
g_print("Could not open base directory.\n");
} else {
while (dirname = (gchar *)g_dir_read_name(dir)) {
fullPath = g_strdup_printf("%s/%s", base_dir, dirname);
@ -359,12 +358,15 @@ static void mdiary_recurse_and_collect(gchar *base_dir,
* @brief mdiary_scan_to_store recursively (max. 5 levels) scans the base_dir into the entryListStore.
* @param base_dir The base directory to start scanning in
* @param entryListStore Target GtkListStore
* @return The amount of entries in the list (total across multiple scans)
*/
void mdiary_scan_to_store(gchar *base_dir, GtkListStore *entryListStore, GtkListStore *autoCompletion)
gint mdiary_scan_to_store(gchar *base_dir, GtkListStore *entryListStore, GtkListStore *autoCompletion)
{
time_earliest = G_MAXINT64;
time_latest = 0;
mdiary_recurse_and_collect(base_dir, entryListStore, autoCompletion, 5);
return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(entryListStore), NULL);
}
/**
@ -500,3 +502,36 @@ 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);
}

View File

@ -16,7 +16,7 @@ enum {
COL_COUNT
};
void mdiary_scan_to_store(gchar *base_dir, GtkListStore *entryListStore, GtkListStore *autoCompletion);
gint mdiary_scan_to_store(gchar *base_dir, GtkListStore *entryListStore, GtkListStore *autoCompletion);
void mdiary_add_entry_to_store(GtkListStore *entryListStore,
GtkListStore *autoCompletion,
gchar *title,
@ -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 */