Compare commits
No commits in common. "686f828c81c33bed3103df2931bec326007d0b0e" and "7a9a5af65b04a7162ffc6795de894f4619a9dab8" have entirely different histories.
686f828c81
...
7a9a5af65b
@ -2,6 +2,11 @@
|
||||
<!-- 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>
|
||||
|
@ -13,6 +13,9 @@ 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;
|
||||
|
@ -431,10 +431,9 @@ 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->chooseDirectoryDialog = GTK_FILE_CHOOSER_DIALOG(gtk_builder_get_object(
|
||||
builder, "chooseDirectoryDialog"));
|
||||
mainWindow->searchEntryCompletion = GTK_ENTRY_COMPLETION(gtk_builder_get_object(builder,
|
||||
"searchEntryCompletion"));
|
||||
|
||||
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"));
|
||||
@ -458,7 +457,6 @@ 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;
|
||||
}
|
||||
@ -477,10 +475,21 @@ 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.
|
||||
@ -679,35 +688,6 @@ 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,
|
||||
@ -724,41 +704,7 @@ 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);
|
||||
mainWindow_switch_workspace(mainWindow, path);
|
||||
g_print("TODO: Switch workspace to %s\n", 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");
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ struct mainWindow {
|
||||
GtkWidget *checkSearchText;
|
||||
GtkWidget *labelSummary;
|
||||
GtkWidget *buttonClearSearch;
|
||||
GtkFileChooserWidget *chooseDirectoryDialog;
|
||||
GtkTreeView *entryListView;
|
||||
GtkTreeSelection *entryListSelection;
|
||||
GtkTextBuffer *textBuffer;
|
||||
@ -62,7 +61,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, gpointer user_data);
|
||||
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gint event, gpointer user_data);
|
||||
void mainWindow_workspaceListClicked(GtkWidget *widget,
|
||||
GtkTreePath *tree_path,
|
||||
GtkTreeViewColumn *column,
|
||||
|
43
src/mdiary.c
43
src/mdiary.c
@ -328,14 +328,15 @@ static void mdiary_recurse_and_collect(gchar *base_dir,
|
||||
GtkListStore *autoCompletion,
|
||||
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 *fullPath;
|
||||
GRegex *regex;
|
||||
GMatchInfo *match_info;
|
||||
|
||||
if (!dir) {
|
||||
g_print("Could not open base directory.\n");
|
||||
g_print("Error, could not open base directory.\n");
|
||||
} else {
|
||||
while (dirname = (gchar *)g_dir_read_name(dir)) {
|
||||
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.
|
||||
* @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)
|
||||
*/
|
||||
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_latest = 0;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ enum {
|
||||
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,
|
||||
GtkListStore *autoCompletion,
|
||||
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);
|
||||
gint64 mdiary_get_time_earliest(void);
|
||||
gint64 mdiary_get_time_latest(void);
|
||||
void mdiary_reset_store(GtkListStore *entryListStore, GtkListStore *autoCompletion);
|
||||
|
||||
#endif /* MDIARY_H */
|
||||
|
Loading…
Reference in New Issue
Block a user