Merge branch 'master' of git.notsyncing.net:markus/mdiary
This commit is contained in:
commit
a6bb0234f7
@ -33,8 +33,13 @@
|
||||
<object class="GtkTreeView" id="treeWorkspace">
|
||||
<property name="visible">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="enable_search">False</property>
|
||||
<property name="fixed_height_mode">True</property>
|
||||
<property name="hover_selection">True</property>
|
||||
<property name="show_expanders">False</property>
|
||||
<property name="enable_grid_lines">horizontal</property>
|
||||
<property name="activate_on_single_click">True</property>
|
||||
<child internal-child="selection">
|
||||
@ -385,7 +390,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<object class="GtkHeaderBar" id="headerBar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title">MDiary</property>
|
||||
|
@ -13,11 +13,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
mainWindow = mainWindow_new();
|
||||
|
||||
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);
|
||||
|
||||
mainWindow = mainWindow_new();
|
||||
gtk_widget_show(mainWindow->mainWindow);
|
||||
gtk_main();
|
||||
|
||||
|
@ -1,12 +1,6 @@
|
||||
#include "mainwindow.h"
|
||||
#include "mdiary.h"
|
||||
|
||||
enum {
|
||||
WSCOL_LABEL = 0,
|
||||
WSCOL_PATH,
|
||||
WSCOL_COUNT
|
||||
};
|
||||
|
||||
static gboolean mainWindow_workspace_entry_visible(GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
struct mainWindow *mainWindow)
|
||||
@ -147,12 +141,13 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
||||
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;
|
||||
GMatchInfo *match_info;
|
||||
gchar *temp;
|
||||
gboolean del_iter = FALSE;
|
||||
|
||||
regex = g_regex_new("(.*)\\/(.*)", G_REGEX_RAW, 0, NULL);
|
||||
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_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>",
|
||||
g_match_info_fetch(match_info, 2),
|
||||
g_match_info_fetch(match_info, 1));
|
||||
if (append)
|
||||
gtk_list_store_append(mainWindow->workspaceListStore, &iter);
|
||||
else
|
||||
gtk_list_store_prepend(mainWindow->workspaceListStore, &iter);
|
||||
gtk_list_store_set(mainWindow->workspaceListStore, &iter,
|
||||
WSCOL_LABEL, temp,
|
||||
WSCOL_PATH, path,
|
||||
-1);
|
||||
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);
|
||||
@ -201,10 +219,6 @@ static void mainWindow_configure_workspaceTreeView(struct mainWindow *mainWindow
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
gtk_tree_view_insert_column_with_attributes(mainWindow->workspaceListView, -1, "", renderer,
|
||||
"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->labelSummary = GTK_WIDGET(gtk_builder_get_object(builder, "labelSummary"));
|
||||
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->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->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"));
|
||||
@ -693,18 +706,22 @@ static void mainWindow_show_error(struct mainWindow *mainWindow, gchar *text)
|
||||
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);
|
||||
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))
|
||||
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_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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,14 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include "mdiary.h"
|
||||
|
||||
#define FILE_LIST_MAX_LEN 5
|
||||
|
||||
enum {
|
||||
WSCOL_LABEL = 0,
|
||||
WSCOL_PATH,
|
||||
WSCOL_COUNT
|
||||
};
|
||||
|
||||
struct mainWindow {
|
||||
GtkWidget *mainWindow;
|
||||
GtkWidget *mainPane;
|
||||
@ -21,7 +29,7 @@ struct mainWindow {
|
||||
GtkWidget *checkSearchText;
|
||||
GtkWidget *labelSummary;
|
||||
GtkWidget *buttonClearSearch;
|
||||
GtkFileChooserWidget *chooseDirectoryDialog;
|
||||
GtkWidget *headerBar;
|
||||
GtkTreeView *entryListView;
|
||||
GtkTreeSelection *entryListSelection;
|
||||
GtkTextBuffer *textBuffer;
|
||||
@ -59,8 +67,6 @@ void mainWindow_set_meta_information(struct mainWindow *mainWindow,
|
||||
guint time_earliest,
|
||||
guint time_latest,
|
||||
gboolean hide_all);
|
||||
|
||||
/* Slots */
|
||||
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data);
|
||||
void mainWindow_otherWorkspaceClicked(GtkWidget *widget, gpointer user_data);
|
||||
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_checkDate(GtkWidget *widget, 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 */
|
||||
|
@ -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) &&
|
||||
g_regex_get_capture_count(regex) > 0 &&
|
||||
g_match_info_matches(match_info)) {
|
||||
settings->last_workspaces = g_list_append(settings->last_workspaces,
|
||||
g_strdup(g_match_info_fetch(match_info, 1)));
|
||||
mainWindow_add_recent_workspace(settings->mainWindow, g_match_info_fetch(match_info, 1), TRUE);
|
||||
}
|
||||
|
||||
g_regex_unref(regex);
|
||||
@ -25,6 +24,9 @@ gboolean mdiary_load_settings(gchar *filename, struct mdiary_settings *settings)
|
||||
GDataInputStream *dstream;
|
||||
gchar *line;
|
||||
|
||||
GtkTreeIter iter;
|
||||
gchar *temp;
|
||||
|
||||
file = g_file_new_for_path(filename);
|
||||
stream = g_file_read(file, NULL, &err);
|
||||
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_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)
|
||||
{
|
||||
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;
|
||||
|
||||
settings = malloc(sizeof(struct mdiary_settings));
|
||||
settings->last_workspaces = NULL;
|
||||
settings->mainWindow = mainWindow;
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
void mdiary_settings_free(struct mdiary_settings *settings)
|
||||
{
|
||||
g_list_free_full(settings->last_workspaces, g_free);
|
||||
free(settings);
|
||||
}
|
||||
|
@ -4,14 +4,15 @@
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
struct mdiary_settings {
|
||||
GList *last_workspaces;
|
||||
struct mainWindow *mainWindow;
|
||||
};
|
||||
|
||||
gboolean mdiary_load_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);
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
Loading…
Reference in New Issue
Block a user