Compare commits

...

8 Commits

6 changed files with 111 additions and 41 deletions

View File

@ -33,8 +33,13 @@
<object class="GtkTreeView" id="treeWorkspace"> <object class="GtkTreeView" id="treeWorkspace">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hscroll_policy">natural</property>
<property name="vscroll_policy">natural</property>
<property name="headers_visible">False</property> <property name="headers_visible">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="hover_selection">True</property> <property name="hover_selection">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">horizontal</property> <property name="enable_grid_lines">horizontal</property>
<property name="activate_on_single_click">True</property> <property name="activate_on_single_click">True</property>
<child internal-child="selection"> <child internal-child="selection">
@ -385,7 +390,7 @@
</object> </object>
</child> </child>
<child type="titlebar"> <child type="titlebar">
<object class="GtkHeaderBar"> <object class="GtkHeaderBar" id="headerBar">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title">MDiary</property> <property name="title">MDiary</property>

View File

@ -13,11 +13,12 @@ int main(int argc, char *argv[])
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
mainWindow = mainWindow_new();
settings_path = g_strdup_printf("%s/.mdiary.conf", g_get_home_dir()); settings_path = g_strdup_printf("%s/.mdiary.conf", g_get_home_dir());
settings = mdiary_settings_new(); settings = mdiary_settings_new(mainWindow);
mdiary_load_settings(settings_path, settings); mdiary_load_settings(settings_path, settings);
mainWindow = mainWindow_new();
gtk_widget_show(mainWindow->mainWindow); gtk_widget_show(mainWindow->mainWindow);
gtk_main(); gtk_main();

View File

@ -1,12 +1,6 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "mdiary.h" #include "mdiary.h"
enum {
WSCOL_LABEL = 0,
WSCOL_PATH,
WSCOL_COUNT
};
static gboolean mainWindow_workspace_entry_visible(GtkTreeModel *model, static gboolean mainWindow_workspace_entry_visible(GtkTreeModel *model,
GtkTreeIter *iter, GtkTreeIter *iter,
struct mainWindow *mainWindow) struct mainWindow *mainWindow)
@ -147,12 +141,13 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
return -1; return -1;
} }
static void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path) void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path, gboolean append)
{ {
GtkTreeIter iter; GtkTreeIter iter, iter_delete;
GRegex *regex; GRegex *regex;
GMatchInfo *match_info; GMatchInfo *match_info;
gchar *temp; gchar *temp;
gboolean del_iter = FALSE;
regex = g_regex_new("(.*)\\/(.*)", G_REGEX_RAW, 0, NULL); regex = g_regex_new("(.*)\\/(.*)", G_REGEX_RAW, 0, NULL);
if (g_regex_match(regex, path, 0, &match_info) && if (g_regex_match(regex, path, 0, &match_info) &&
@ -160,15 +155,38 @@ static void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar
g_match_info_matches(match_info)) { g_match_info_matches(match_info)) {
g_match_info_fetch(match_info, 1); g_match_info_fetch(match_info, 1);
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter)) {
do {
memcpy(&iter_delete, &iter, sizeof(iter)); /* scan for last */
gtk_tree_model_get(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter,
WSCOL_PATH, &temp,
-1);
if (!g_strcmp0(temp, path)) {
g_free(temp);
gtk_list_store_remove(mainWindow->workspaceListStore, &iter);
break;
}
g_free(temp);
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(mainWindow->workspaceListStore), &iter));
}
temp = g_strdup_printf("<b>%s</b>\n<span weight=\"ultralight\">%s</span>", temp = g_strdup_printf("<b>%s</b>\n<span weight=\"ultralight\">%s</span>",
g_match_info_fetch(match_info, 2), g_match_info_fetch(match_info, 2),
g_match_info_fetch(match_info, 1)); g_match_info_fetch(match_info, 1));
gtk_list_store_append(mainWindow->workspaceListStore, &iter); if (append)
gtk_list_store_append(mainWindow->workspaceListStore, &iter);
else
gtk_list_store_prepend(mainWindow->workspaceListStore, &iter);
gtk_list_store_set(mainWindow->workspaceListStore, &iter, gtk_list_store_set(mainWindow->workspaceListStore, &iter,
WSCOL_LABEL, temp, WSCOL_LABEL, temp,
WSCOL_PATH, path, WSCOL_PATH, path,
-1); -1);
g_free(temp); g_free(temp);
if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(mainWindow->workspaceListStore), NULL)
> FILE_LIST_MAX_LEN)
gtk_list_store_remove(mainWindow->workspaceListStore, &iter_delete);
} }
g_regex_unref(regex); g_regex_unref(regex);
@ -188,9 +206,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,
@ -201,10 +219,6 @@ static void mainWindow_configure_workspaceTreeView(struct mainWindow *mainWindow
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(mainWindow->workspaceListView, -1, "", renderer, gtk_tree_view_insert_column_with_attributes(mainWindow->workspaceListView, -1, "", renderer,
"markup", WSCOL_LABEL, NULL); "markup", WSCOL_LABEL, NULL);
/* Test only */
mainWindow_add_recent_workspace(mainWindow, "/home/user/Document/diary");
mainWindow_add_recent_workspace(mainWindow, "/home/user/Document/workfoo");
} }
/** /**
@ -428,13 +442,12 @@ struct mainWindow *mainWindow_new()
mainWindow->checkSearchText = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchText")); mainWindow->checkSearchText = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchText"));
mainWindow->labelSummary = GTK_WIDGET(gtk_builder_get_object(builder, "labelSummary")); mainWindow->labelSummary = GTK_WIDGET(gtk_builder_get_object(builder, "labelSummary"));
mainWindow->buttonClearSearch = GTK_WIDGET(gtk_builder_get_object(builder, "buttonClearSearch")); mainWindow->buttonClearSearch = GTK_WIDGET(gtk_builder_get_object(builder, "buttonClearSearch"));
mainWindow->headerBar = GTK_WIDGET(gtk_builder_get_object(builder, "headerBar"));
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, "searchEntryCompletion")); 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->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"));
@ -602,13 +615,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);
} }
@ -693,18 +706,22 @@ static void mainWindow_show_error(struct mainWindow *mainWindow, gchar *text)
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
} }
static void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path) void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path)
{ {
g_print("Switching workspace to %s.\n", path); g_print("Switching workspace to %s.\n", path);
gtk_popover_popdown(GTK_POPOVER(mainWindow->popoverWorkspace)); gtk_popover_popdown(GTK_POPOVER(mainWindow->popoverWorkspace));
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE); mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
mdiary_reset_store(mainWindow->entryListStore, mainWindow->completionListStore); mdiary_reset_store(mainWindow->entryListStore, mainWindow->completionListStore);
if (mdiary_scan_to_store(path, mainWindow->entryListStore, mainWindow->completionListStore)) if (mdiary_scan_to_store(path, mainWindow->entryListStore, mainWindow->completionListStore)) {
mainWindow_set_meta_information(mainWindow, mainWindow_set_meta_information(mainWindow,
mdiary_get_time_earliest(), mdiary_get_time_latest(), mdiary_get_time_earliest(), mdiary_get_time_latest(),
FALSE); FALSE);
else mainWindow_add_recent_workspace(mainWindow, path, FALSE);
gtk_header_bar_set_subtitle(GTK_HEADER_BAR(mainWindow->headerBar), path);
} else {
gtk_header_bar_set_subtitle(GTK_HEADER_BAR(mainWindow->headerBar), "No workspace opened.");
mainWindow_show_error(mainWindow, "Could not open workspace or no entries were found in it."); mainWindow_show_error(mainWindow, "Could not open workspace or no entries were found in it.");
}
} }
@ -752,9 +769,9 @@ void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gpointer user_data)
if (res == GTK_RESPONSE_ACCEPT) { if (res == GTK_RESPONSE_ACCEPT) {
char *directory; char *directory;
directory = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)); directory = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
mainWindow_switch_workspace(mainWindow, directory); mainWindow_switch_workspace(mainWindow, directory);
g_free (directory); g_free(directory);
} }
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);

View File

@ -6,6 +6,14 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "mdiary.h" #include "mdiary.h"
#define FILE_LIST_MAX_LEN 5
enum {
WSCOL_LABEL = 0,
WSCOL_PATH,
WSCOL_COUNT
};
struct mainWindow { struct mainWindow {
GtkWidget *mainWindow; GtkWidget *mainWindow;
GtkWidget *mainPane; GtkWidget *mainPane;
@ -21,7 +29,7 @@ struct mainWindow {
GtkWidget *checkSearchText; GtkWidget *checkSearchText;
GtkWidget *labelSummary; GtkWidget *labelSummary;
GtkWidget *buttonClearSearch; GtkWidget *buttonClearSearch;
GtkFileChooserWidget *chooseDirectoryDialog; GtkWidget *headerBar;
GtkTreeView *entryListView; GtkTreeView *entryListView;
GtkTreeSelection *entryListSelection; GtkTreeSelection *entryListSelection;
GtkTextBuffer *textBuffer; GtkTextBuffer *textBuffer;
@ -59,8 +67,6 @@ void mainWindow_set_meta_information(struct mainWindow *mainWindow,
guint time_earliest, guint time_earliest,
guint time_latest, guint time_latest,
gboolean hide_all); gboolean hide_all);
/* 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, gpointer user_data);
void mainWindow_workspaceListClicked(GtkWidget *widget, void mainWindow_workspaceListClicked(GtkWidget *widget,
@ -74,5 +80,7 @@ void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data);
void mainWindow_workspace_search_changed(GtkWidget *widget, gpointer user_data); void mainWindow_workspace_search_changed(GtkWidget *widget, gpointer user_data);
void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data); void mainWindow_checkDate(GtkWidget *widget, gint event, gpointer user_data);
void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpointer user_data); void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpointer user_data);
void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path, gboolean append);
void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path);
#endif /* MAINWINDOW_H */ #endif /* MAINWINDOW_H */

View File

@ -10,8 +10,7 @@ static void mdiary_settings_parse_line(gchar *line, struct mdiary_settings *sett
if (g_regex_match(regex, line, 0, &match_info) && if (g_regex_match(regex, line, 0, &match_info) &&
g_regex_get_capture_count(regex) > 0 && g_regex_get_capture_count(regex) > 0 &&
g_match_info_matches(match_info)) { g_match_info_matches(match_info)) {
settings->last_workspaces = g_list_append(settings->last_workspaces, mainWindow_add_recent_workspace(settings->mainWindow, g_match_info_fetch(match_info, 1), TRUE);
g_strdup(g_match_info_fetch(match_info, 1)));
} }
g_regex_unref(regex); g_regex_unref(regex);
@ -25,6 +24,9 @@ gboolean mdiary_load_settings(gchar *filename, struct mdiary_settings *settings)
GDataInputStream *dstream; GDataInputStream *dstream;
gchar *line; gchar *line;
GtkTreeIter iter;
gchar *temp;
file = g_file_new_for_path(filename); file = g_file_new_for_path(filename);
stream = g_file_read(file, NULL, &err); stream = g_file_read(file, NULL, &err);
if (err != NULL) { if (err != NULL) {
@ -42,24 +44,60 @@ gboolean mdiary_load_settings(gchar *filename, struct mdiary_settings *settings)
g_input_stream_close(G_INPUT_STREAM(stream), NULL, NULL); g_input_stream_close(G_INPUT_STREAM(stream), NULL, NULL);
g_object_unref(file); g_object_unref(file);
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(settings->mainWindow->workspaceListStore), &iter)) {
gtk_tree_model_get(GTK_TREE_MODEL(settings->mainWindow->workspaceListStore), &iter,
WSCOL_PATH, &temp,
-1);
mainWindow_switch_workspace(settings->mainWindow, temp);
g_free(temp);
}
} }
gboolean mdiary_save_settings(gchar *filename, struct mdiary_settings *settings) gboolean mdiary_save_settings(gchar *filename, struct mdiary_settings *settings)
{ {
g_print("SETTINGS: NYI.\n"); GtkTreeIter iter;
gchar *temp;
gchar *output_buffer;
GFileOutputStream *stream;
GFile *file;
file = g_file_new_for_path(filename);
stream = g_file_replace(
file, NULL, FALSE,
G_FILE_CREATE_NONE,
NULL, NULL);
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(settings->mainWindow->workspaceListStore), &iter)) {
do {
gtk_tree_model_get(GTK_TREE_MODEL(settings->mainWindow->workspaceListStore), &iter,
WSCOL_PATH, &temp,
-1);
output_buffer = g_strdup_printf("workspace = %s\n", temp);
g_output_stream_write(G_OUTPUT_STREAM(stream),
output_buffer, strlen(output_buffer), NULL, NULL);
g_free(output_buffer);
g_free(temp);
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(settings->mainWindow->workspaceListStore), &iter));
}
g_output_stream_close(G_OUTPUT_STREAM(stream),NULL,NULL);
g_object_unref(stream);
g_object_unref(file);
} }
struct mdiary_settings *mdiary_settings_new() struct mdiary_settings *mdiary_settings_new(struct mainWindow *mainWindow)
{ {
struct mdiary_settings *settings; struct mdiary_settings *settings;
settings = malloc(sizeof(struct mdiary_settings)); settings = malloc(sizeof(struct mdiary_settings));
settings->last_workspaces = NULL; settings->mainWindow = mainWindow;
return settings; return settings;
} }
void mdiary_settings_free(struct mdiary_settings *settings) void mdiary_settings_free(struct mdiary_settings *settings)
{ {
g_list_free_full(settings->last_workspaces, g_free); free(settings);
} }

View File

@ -4,14 +4,15 @@
#include <glib.h> #include <glib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <stdlib.h> #include <stdlib.h>
#include "mainwindow.h"
struct mdiary_settings { struct mdiary_settings {
GList *last_workspaces; struct mainWindow *mainWindow;
}; };
gboolean mdiary_load_settings(gchar *filename, struct mdiary_settings *settings); gboolean mdiary_load_settings(gchar *filename, struct mdiary_settings *settings);
gboolean mdiary_save_settings(gchar *filename, struct mdiary_settings *settings); gboolean mdiary_save_settings(gchar *filename, struct mdiary_settings *settings);
struct mdiary_settings *mdiary_settings_new(); struct mdiary_settings *mdiary_settings_new(struct mainWindow *mainWindow);
void mdiary_settings_free(struct mdiary_settings *settings); void mdiary_settings_free(struct mdiary_settings *settings);
#endif // SETTINGS_H #endif // SETTINGS_H