Compare commits
No commits in common. "f444d40071fa394a6c8cb433750db7bfe49469cb" and "d066bdde5811057dbe2eb3955ea33a98049b1f8d" have entirely different histories.
f444d40071
...
d066bdde58
@ -33,13 +33,8 @@
|
||||
<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">
|
||||
@ -390,7 +385,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar" id="headerBar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title">MDiary</property>
|
||||
|
@ -13,12 +13,11 @@ 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(mainWindow);
|
||||
settings = mdiary_settings_new();
|
||||
mdiary_load_settings(settings_path, settings);
|
||||
|
||||
mainWindow = mainWindow_new();
|
||||
gtk_widget_show(mainWindow->mainWindow);
|
||||
gtk_main();
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
#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)
|
||||
@ -141,13 +147,12 @@ static gint mainWindow_sort_date_compare_func(GtkTreeModel *model,
|
||||
return -1;
|
||||
}
|
||||
|
||||
void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path, gboolean append)
|
||||
static void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path)
|
||||
{
|
||||
GtkTreeIter iter, iter_delete;
|
||||
GtkTreeIter iter;
|
||||
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) &&
|
||||
@ -155,38 +160,15 @@ void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path,
|
||||
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);
|
||||
@ -219,6 +201,10 @@ 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");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -442,12 +428,13 @@ 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"));
|
||||
@ -706,22 +693,18 @@ static void mainWindow_show_error(struct mainWindow *mainWindow, gchar *text)
|
||||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path)
|
||||
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)) {
|
||||
if (mdiary_scan_to_store(path, mainWindow->entryListStore, mainWindow->completionListStore))
|
||||
mainWindow_set_meta_information(mainWindow,
|
||||
mdiary_get_time_earliest(), mdiary_get_time_latest(),
|
||||
FALSE);
|
||||
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.");
|
||||
else
|
||||
mainWindow_show_error(mainWindow, "Could not open workspace or no entries were found in it.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,6 @@
|
||||
#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;
|
||||
@ -29,7 +21,7 @@ struct mainWindow {
|
||||
GtkWidget *checkSearchText;
|
||||
GtkWidget *labelSummary;
|
||||
GtkWidget *buttonClearSearch;
|
||||
GtkWidget *headerBar;
|
||||
GtkFileChooserWidget *chooseDirectoryDialog;
|
||||
GtkTreeView *entryListView;
|
||||
GtkTreeSelection *entryListSelection;
|
||||
GtkTextBuffer *textBuffer;
|
||||
@ -67,6 +59,8 @@ 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,
|
||||
@ -80,7 +74,5 @@ 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,7 +10,8 @@ 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)) {
|
||||
mainWindow_add_recent_workspace(settings->mainWindow, g_match_info_fetch(match_info, 1), TRUE);
|
||||
settings->last_workspaces = g_list_append(settings->last_workspaces,
|
||||
g_strdup(g_match_info_fetch(match_info, 1)));
|
||||
}
|
||||
|
||||
g_regex_unref(regex);
|
||||
@ -24,9 +25,6 @@ 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) {
|
||||
@ -44,60 +42,24 @@ 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)
|
||||
{
|
||||
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);
|
||||
g_print("SETTINGS: NYI.\n");
|
||||
}
|
||||
|
||||
struct mdiary_settings *mdiary_settings_new(struct mainWindow *mainWindow)
|
||||
struct mdiary_settings *mdiary_settings_new()
|
||||
{
|
||||
struct mdiary_settings *settings;
|
||||
|
||||
settings = malloc(sizeof(struct mdiary_settings));
|
||||
settings->mainWindow = mainWindow;
|
||||
settings->last_workspaces = NULL;
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
void mdiary_settings_free(struct mdiary_settings *settings)
|
||||
{
|
||||
free(settings);
|
||||
g_list_free_full(settings->last_workspaces, g_free);
|
||||
}
|
||||
|
@ -4,15 +4,14 @@
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
struct mdiary_settings {
|
||||
struct mainWindow *mainWindow;
|
||||
GList *last_workspaces;
|
||||
};
|
||||
|
||||
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 mainWindow *mainWindow);
|
||||
struct mdiary_settings *mdiary_settings_new();
|
||||
void mdiary_settings_free(struct mdiary_settings *settings);
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
Loading…
Reference in New Issue
Block a user