Compare commits

..

No commits in common. "686f828c81c33bed3103df2931bec326007d0b0e" and "7a9a5af65b04a7162ffc6795de894f4619a9dab8" have entirely different histories.

6 changed files with 37 additions and 120 deletions

View File

@ -2,6 +2,11 @@
<!-- Generated with glade 3.20.0 --> <!-- Generated with glade 3.20.0 -->
<interface> <interface>
<requires lib="gtk+" version="3.20"/> <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="GtkTextBuffer" id="entryTextBuffer"/>
<object class="GtkPopover" id="popoverWorkspace"> <object class="GtkPopover" id="popoverWorkspace">
<property name="can_focus">False</property> <property name="can_focus">False</property>

View File

@ -13,6 +13,9 @@ int main(int argc, char *argv[])
mainWindow = mainWindow_new(); mainWindow = mainWindow_new();
gtk_widget_show(mainWindow->mainWindow); 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(); gtk_main();
return 0; return 0;

View File

@ -188,9 +188,9 @@ static void mainWindow_configure_workspaceTreeView(struct mainWindow *mainWindow
G_TYPE_STRING); G_TYPE_STRING);
mainWindow->workspaceListFiltered = GTK_TREE_MODEL_FILTER( mainWindow->workspaceListFiltered = GTK_TREE_MODEL_FILTER(
gtk_tree_model_filter_new( gtk_tree_model_filter_new(
GTK_TREE_MODEL(mainWindow->workspaceListStore), GTK_TREE_MODEL(mainWindow->workspaceListStore),
NULL)); NULL));
gtk_tree_model_filter_set_visible_func(mainWindow->workspaceListFiltered, gtk_tree_model_filter_set_visible_func(mainWindow->workspaceListFiltered,
(GtkTreeModelFilterVisibleFunc) mainWindow_workspace_entry_visible, (GtkTreeModelFilterVisibleFunc) mainWindow_workspace_entry_visible,
@ -431,10 +431,9 @@ struct mainWindow *mainWindow_new()
mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView")); mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView"));
mainWindow->entryListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder, "entryListSelection")); mainWindow->entryListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder, "entryListSelection"));
mainWindow->textBuffer = GTK_TEXT_BUFFER(gtk_builder_get_object(builder, "entryTextBuffer")); mainWindow->textBuffer = GTK_TEXT_BUFFER(gtk_builder_get_object(builder, "entryTextBuffer"));
mainWindow->searchEntryCompletion = GTK_ENTRY_COMPLETION(gtk_builder_get_object( mainWindow->searchEntryCompletion = GTK_ENTRY_COMPLETION(gtk_builder_get_object(builder,
builder, "searchEntryCompletion")); "searchEntryCompletion"));
mainWindow->chooseDirectoryDialog = GTK_FILE_CHOOSER_DIALOG(gtk_builder_get_object(
builder, "chooseDirectoryDialog"));
mainWindow->buttonOtherWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "buttonOtherWorkspace")); mainWindow->buttonOtherWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "buttonOtherWorkspace"));
mainWindow->workspaceSearch = GTK_WIDGET(gtk_builder_get_object(builder, "searchWorkspace")); mainWindow->workspaceSearch = GTK_WIDGET(gtk_builder_get_object(builder, "searchWorkspace"));
mainWindow->popoverWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "popoverWorkspace")); mainWindow->popoverWorkspace = GTK_WIDGET(gtk_builder_get_object(builder, "popoverWorkspace"));
@ -458,7 +457,6 @@ struct mainWindow *mainWindow_new()
mainWindow_init_to_default(mainWindow); mainWindow_init_to_default(mainWindow);
mainWindow_clearSearch(NULL, mainWindow); mainWindow_clearSearch(NULL, mainWindow);
mainWindow_configure_entry_completion(mainWindow); mainWindow_configure_entry_completion(mainWindow);
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
return mainWindow; return mainWindow;
} }
@ -477,10 +475,21 @@ void mainWindow_set_meta_information(struct mainWindow *mainWindow,
mainWindow->time_earliest = time_earliest; mainWindow->time_earliest = time_earliest;
mainWindow->time_latest = time_latest; mainWindow->time_latest = time_latest;
mainWindow->filterSettings.hide_all = hide_all; mainWindow->filterSettings.hide_all = hide_all;
gtk_widget_set_sensitive(mainWindow->mainPane, !hide_all);
mainWindow_clearSearch(NULL, mainWindow); 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. * @brief mainWindow_showPopover is called from a dateEntry when it is focused.
* @param widget is the text entry. * @param widget is the text entry.
@ -602,13 +611,13 @@ void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data)
} }
mainWindow->filterSettings.search_title = gtk_toggle_button_get_active( 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( 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( 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( 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); gtk_tree_model_filter_refilter(mainWindow->entryListFiltered);
} }
@ -679,35 +688,6 @@ void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpoi
mainWindow_clearSearch(widget, user_data); 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, void mainWindow_workspaceListClicked(GtkWidget *widget,
GtkTreePath *tree_path, GtkTreePath *tree_path,
GtkTreeViewColumn *column, GtkTreeViewColumn *column,
@ -724,41 +704,7 @@ void mainWindow_workspaceListClicked(GtkWidget *widget,
selection = gtk_tree_view_get_selection(mainWindow->workspaceListView); selection = gtk_tree_view_get_selection(mainWindow->workspaceListView);
if (gtk_tree_selection_get_selected(selection, &model, &iter)) { if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
gtk_tree_model_get(model, &iter, WSCOL_PATH, &path, -1); gtk_tree_model_get(model, &iter, WSCOL_PATH, &path, -1);
mainWindow_switch_workspace(mainWindow, path); g_print("TODO: Switch workspace to %s\n", path);
g_free(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,7 +21,6 @@ struct mainWindow {
GtkWidget *checkSearchText; GtkWidget *checkSearchText;
GtkWidget *labelSummary; GtkWidget *labelSummary;
GtkWidget *buttonClearSearch; GtkWidget *buttonClearSearch;
GtkFileChooserWidget *chooseDirectoryDialog;
GtkTreeView *entryListView; GtkTreeView *entryListView;
GtkTreeSelection *entryListSelection; GtkTreeSelection *entryListSelection;
GtkTextBuffer *textBuffer; GtkTextBuffer *textBuffer;
@ -62,7 +61,7 @@ void mainWindow_set_meta_information(struct mainWindow *mainWindow,
/* Slots */ /* Slots */
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data); void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data);
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gpointer user_data); void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data);
void mainWindow_workspaceListClicked(GtkWidget *widget, void mainWindow_workspaceListClicked(GtkWidget *widget,
GtkTreePath *tree_path, GtkTreePath *tree_path,
GtkTreeViewColumn *column, GtkTreeViewColumn *column,

View File

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