Compare commits

..

No commits in common. "a6299aa7ac6f9af6c30a6513ee249a8feb7f2271" and "2d8d86781c127b466614592699ef97371d1a9387" have entirely different histories.

4 changed files with 31 additions and 200 deletions

View File

@ -492,58 +492,4 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkWindow" id="settingsDialog">
<property name="can_focus">False</property>
<property name="destroy_with_parent">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">4</property>
<property name="margin_right">4</property>
<property name="margin_top">4</property>
<property name="margin_bottom">4</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Entry display mode:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="comboDisplayMode">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface> </interface>

View File

@ -5,11 +5,6 @@
#include "mdiary.h" #include "mdiary.h"
#include "settings.h" #include "settings.h"
struct app_state {
struct mainWindow *mainWindow;
struct mdiary_settings *settings;
};
static void quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) static void quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{ {
struct mainWindow *mainWindow = *((struct mainWindow **) user_data); struct mainWindow *mainWindow = *((struct mainWindow **) user_data);
@ -20,9 +15,8 @@ static void quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_da
static void settings_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) static void settings_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{ {
struct mainWindow *mainWindow = *((struct mainWindow **) user_data); struct mainWindow *mainWindow = *((struct mainWindow **) user_data);
struct mainWindow *a = user_data;
mainWindow_settings_show(mainWindow); g_print("nTODO\n");
} }
const GActionEntry app_actions[] = { const GActionEntry app_actions[] = {
@ -32,38 +26,27 @@ const GActionEntry app_actions[] = {
static void activate(GApplication *app, gpointer user_data) static void activate(GApplication *app, gpointer user_data)
{ {
struct app_state *app_state = user_data; struct mainWindow *mainWindow = *((struct mainWindow **) user_data);
struct mainWindow **mainWindow = &(app_state->mainWindow); struct mdiary_settings *settings;
struct mdiary_settings **settings = &(app_state->settings);
gchar *settings_path; gchar *settings_path;
*mainWindow = mainWindow_new(); mainWindow = mainWindow_new();
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW((*mainWindow)->mainWindow)); gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(mainWindow->mainWindow));
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(*mainWindow); settings = mdiary_settings_new(mainWindow);
mdiary_load_settings(settings_path, *settings); mdiary_load_settings(settings_path, settings);
g_free(settings_path);
gtk_widget_show((*mainWindow)->mainWindow); gtk_widget_show(mainWindow->mainWindow);
}
static void shutdown(GApplication *app, gpointer user_data) mdiary_save_settings(settings_path, settings);
{ mdiary_settings_free(settings);
struct app_state *app_state = user_data;
struct mainWindow **mainWindow = &(app_state->mainWindow);
struct mdiary_settings **settings = &(app_state->settings);
gchar *settings_path;
settings_path = g_strdup_printf("%s/.mdiary.conf", g_get_home_dir());
mdiary_save_settings(settings_path, *settings);
mdiary_settings_free(*settings);
g_free(settings_path); g_free(settings_path);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct app_state app_state; struct mainWindow *mainWindow;
GtkApplication *app; GtkApplication *app;
GMenu *app_menu; GMenu *app_menu;
GMenu *p1; GMenu *p1;
@ -72,8 +55,7 @@ int main(int argc, char *argv[])
app = gtk_application_new("net.notsyncing.mdiary", G_APPLICATION_FLAGS_NONE); app = gtk_application_new("net.notsyncing.mdiary", G_APPLICATION_FLAGS_NONE);
g_application_register(G_APPLICATION(app), NULL, NULL); g_application_register(G_APPLICATION(app), NULL, NULL);
g_signal_connect(app, "activate", G_CALLBACK(activate), &app_state); g_signal_connect(app, "activate", G_CALLBACK(activate), &mainWindow);
g_signal_connect(app, "shutdown", G_CALLBACK(shutdown), &app_state);
app_menu = g_menu_new(); app_menu = g_menu_new();
p1 = g_menu_new(); p1 = g_menu_new();
@ -83,7 +65,7 @@ int main(int argc, char *argv[])
g_menu_append_section(app_menu, NULL, G_MENU_MODEL(p1)); g_menu_append_section(app_menu, NULL, G_MENU_MODEL(p1));
g_menu_append_section(app_menu, NULL, G_MENU_MODEL(p2)); g_menu_append_section(app_menu, NULL, G_MENU_MODEL(p2));
gtk_application_set_app_menu(app, G_MENU_MODEL(app_menu)); gtk_application_set_app_menu(app, G_MENU_MODEL(app_menu));
g_action_map_add_action_entries(G_ACTION_MAP(app), app_actions, G_N_ELEMENTS(app_actions), &app_state); g_action_map_add_action_entries(G_ACTION_MAP(app), app_actions, G_N_ELEMENTS(app_actions), &mainWindow);
gtk_application_set_app_menu(GTK_APPLICATION(app), G_MENU_MODEL(app_menu)); gtk_application_set_app_menu(GTK_APPLICATION(app), G_MENU_MODEL(app_menu));
g_object_unref(p1); g_object_unref(p1);
g_object_unref(p2); g_object_unref(p2);

View File

@ -430,9 +430,9 @@ static void mainWindow_init_to_default(struct mainWindow *mainWindow)
* @param mainWindow the mainWindow * @param mainWindow the mainWindow
* @param state * @param state
*/ */
void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode state) void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state)
{ {
if (state == RENDERER_HTML) { if (state) {
if (!mainWindow->webkitView) { if (!mainWindow->webkitView) {
mainWindow->webkitView = webkit_web_view_new(); mainWindow->webkitView = webkit_web_view_new();
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView), "", ""); webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView), "", "");
@ -450,66 +450,6 @@ void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode s
gtk_stack_set_visible_child(GTK_STACK(mainWindow->stackRenderMode), gtk_stack_set_visible_child(GTK_STACK(mainWindow->stackRenderMode),
mainWindow->entryTextScrollArea); mainWindow->entryTextScrollArea);
} }
mainWindow->renderer = state;
}
static void mainWindow_settings_combo_changed(GtkComboBox *widget, gpointer user_data)
{
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
if (!strcmp(gtk_combo_box_get_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode)), "text"))
mainWindow_renderer_set(mainWindow, RENDERER_TEXT);
else if (!strcmp(gtk_combo_box_get_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode)), "basic"))
mainWindow_renderer_set(mainWindow, RENDERER_BASIC);
else if (!strcmp(gtk_combo_box_get_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode)), "html"))
mainWindow_renderer_set(mainWindow, RENDERER_HTML);
mainWindow_entrySelected(NULL, user_data);
}
static gboolean mainWindow_settings_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
gtk_widget_hide(widget);
return TRUE;
}
void mainWindow_settings_show(struct mainWindow *mainWindow)
{
switch (mainWindow->renderer) {
case RENDERER_TEXT:
gtk_combo_box_set_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode), "text");
break;
case RENDERER_BASIC:
gtk_combo_box_set_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode), "basic");
break;
case RENDERER_HTML:
gtk_combo_box_set_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode), "html");
break;
default:
break;
}
gtk_widget_show(mainWindow->settingsDialog.settingsDialog);
}
static void mainWindow_configure_settings_dialog(struct mainWindow *mainWindow)
{
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mainWindow->settingsDialog.comboDisplayMode),
"text", "Text only");
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mainWindow->settingsDialog.comboDisplayMode),
"basic", "Basic formatting");
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mainWindow->settingsDialog.comboDisplayMode),
"html", "Full HTML with images");
g_signal_connect(mainWindow->settingsDialog.comboDisplayMode,
"changed",
(GCallback) mainWindow_settings_combo_changed,
mainWindow);
g_signal_connect(mainWindow->settingsDialog.settingsDialog,
"delete-event",
(GCallback) mainWindow_settings_delete_event,
mainWindow);
} }
/** /**
@ -555,9 +495,6 @@ struct mainWindow *mainWindow_new()
mainWindow->workspaceListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder, mainWindow->workspaceListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder,
"treeWorkspaceSelection")); "treeWorkspaceSelection"));
mainWindow->settingsDialog.settingsDialog = GTK_WIDGET(gtk_builder_get_object(builder, "settingsDialog"));
mainWindow->settingsDialog.comboDisplayMode = GTK_WIDGET(gtk_builder_get_object(builder, "comboDisplayMode"));
mainWindow->filterSettings.time_start = 0; mainWindow->filterSettings.time_start = 0;
mainWindow->filterSettings.time_end = -1; mainWindow->filterSettings.time_end = -1;
mainWindow->filterSettings.hide_all = TRUE; mainWindow->filterSettings.hide_all = TRUE;
@ -569,7 +506,6 @@ struct mainWindow *mainWindow_new()
g_object_unref(G_OBJECT(builder)); g_object_unref(G_OBJECT(builder));
mainWindow_configure_treeView(mainWindow); mainWindow_configure_treeView(mainWindow);
mainWindow_configure_settings_dialog(mainWindow);
mainWindow->webkitView = NULL; mainWindow->webkitView = NULL;
mainWindow->webkitScrollArea = NULL; mainWindow->webkitScrollArea = NULL;
mainWindow_connect_signals(mainWindow); mainWindow_connect_signals(mainWindow);
@ -579,7 +515,7 @@ struct mainWindow *mainWindow_new()
mainWindow_configure_entry_completion(mainWindow); mainWindow_configure_entry_completion(mainWindow);
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE); mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
mainWindow_renderer_set(mainWindow, RENDERER_HTML); mainWindow_webkit_set_enabled(mainWindow, TRUE);
return mainWindow; return mainWindow;
} }
@ -665,12 +601,11 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
gchar *cmd_stderr = NULL; gchar *cmd_stderr = NULL;
gint exit_status = 0; gint exit_status = 0;
gchar *base_url = NULL; gchar *base_url = NULL;
GFileOutputStream *stream = NULL; GFileOutputStream *stream;
GFile *file = NULL; GFile *file;
if (mainWindow->renderer == RENDERER_TEXT) { if (mainWindow->webkitView &&
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text)); gtk_stack_get_visible_child(GTK_STACK(mainWindow->stackRenderMode)) == mainWindow->webkitScrollArea) {
} else {
if (text[0] != '\0') { if (text[0] != '\0') {
base_url = g_strdup_printf("file://%s", file_url); base_url = g_strdup_printf("file://%s", file_url);
file = g_file_new_for_path(tempfile_path); file = g_file_new_for_path(tempfile_path);
@ -684,28 +619,12 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
cmd = g_strdup_printf("markdown %s", tempfile_path); cmd = g_strdup_printf("markdown %s", tempfile_path);
if (g_spawn_command_line_sync(cmd, &cmd_stdout, &cmd_stderr, &exit_status, NULL) && if (g_spawn_command_line_sync(cmd, &cmd_stdout, &cmd_stderr, &exit_status, NULL) &&
exit_status == 0) { exit_status == 0) {
if (mainWindow->renderer == RENDERER_BASIC) { webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
/* TODO: This renderer is broken. Pango does not like HTML... */ cmd_stdout, base_url);
GtkTextIter iter;
gtk_text_buffer_set_text(mainWindow->textBuffer, "", 0);
gtk_text_buffer_get_start_iter(mainWindow->textBuffer, &iter);
gtk_text_buffer_insert_markup(mainWindow->textBuffer,
&iter,
cmd_stdout,
strlen(cmd_stdout));
} else {
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
cmd_stdout, base_url);
}
} else { } else {
g_warning("Could not render markdown for file. Showing plain text instead.\n"); g_warning("Could not render markdown for file. Showing plain text instead.\n");
if (mainWindow->renderer == RENDERER_BASIC) { webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
gtk_text_buffer_set_text(mainWindow->textBuffer, text, "");
cmd_stdout, strlen(cmd_stdout));
} else {
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
text, base_url);
}
} }
g_free(base_url); g_free(base_url);
} else { } else {
@ -713,17 +632,15 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
text, ""); text, "");
} }
if (stream) { g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL); g_file_delete(file, NULL, NULL);
g_object_unref(stream); g_object_unref(stream);
} g_object_unref(file);
if (file) {
g_file_delete(file, NULL, NULL);
g_object_unref(file);
}
g_free(cmd); g_free(cmd);
g_free(cmd_stdout); g_free(cmd_stdout);
g_free(cmd_stderr); g_free(cmd_stderr);
} else {
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
} }
} }

View File

@ -15,12 +15,6 @@ enum {
WSCOL_COUNT WSCOL_COUNT
}; };
enum renderer_mode {
RENDERER_TEXT = 0,
RENDERER_BASIC,
RENDERER_HTML
};
struct mainWindow { struct mainWindow {
GtkWidget *mainWindow; GtkWidget *mainWindow;
GtkWidget *mainPane; GtkWidget *mainPane;
@ -53,8 +47,6 @@ struct mainWindow {
GtkWidget *selectedDateEntry; GtkWidget *selectedDateEntry;
GtkTreeModelFilter *entryListFiltered; GtkTreeModelFilter *entryListFiltered;
enum renderer_mode renderer;
gint64 time_earliest; gint64 time_earliest;
gint64 time_latest; gint64 time_latest;
@ -75,11 +67,6 @@ struct mainWindow {
GtkTreeSelection *workspaceListSelection; GtkTreeSelection *workspaceListSelection;
GtkListStore *workspaceListStore; GtkListStore *workspaceListStore;
GtkTreeModelFilter *workspaceListFiltered; GtkTreeModelFilter *workspaceListFiltered;
struct settingsDialog {
GtkWidget *settingsDialog;
GtkWidget *comboDisplayMode;
} settingsDialog;
}; };
struct mainWindow *mainWindow_new(); struct mainWindow *mainWindow_new();
@ -103,7 +90,6 @@ void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpoi
void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path, gboolean append); void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path, gboolean append);
void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path, gboolean gpg_enabled); void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path, gboolean gpg_enabled);
void mainWindow_decrypt_gpg_clicked(GtkWidget *widget, gpointer user_data); void mainWindow_decrypt_gpg_clicked(GtkWidget *widget, gpointer user_data);
void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode state); void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state);
void mainWindow_settings_show(struct mainWindow *mainWindow);
#endif /* MAINWINDOW_H */ #endif /* MAINWINDOW_H */