Added additional render mode + settings dialog
This commit is contained in:
parent
3e03b512e1
commit
a6299aa7ac
@ -492,4 +492,58 @@
|
||||
</object>
|
||||
</child>
|
||||
</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>
|
||||
|
@ -20,8 +20,9 @@ static void quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_da
|
||||
static void settings_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||
{
|
||||
struct mainWindow *mainWindow = *((struct mainWindow **) user_data);
|
||||
struct mainWindow *a = user_data;
|
||||
|
||||
g_print("nTODO\n");
|
||||
mainWindow_settings_show(mainWindow);
|
||||
}
|
||||
|
||||
const GActionEntry app_actions[] = {
|
||||
|
117
src/mainwindow.c
117
src/mainwindow.c
@ -430,9 +430,9 @@ static void mainWindow_init_to_default(struct mainWindow *mainWindow)
|
||||
* @param mainWindow the mainWindow
|
||||
* @param state
|
||||
*/
|
||||
void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state)
|
||||
void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode state)
|
||||
{
|
||||
if (state) {
|
||||
if (state == RENDERER_HTML) {
|
||||
if (!mainWindow->webkitView) {
|
||||
mainWindow->webkitView = webkit_web_view_new();
|
||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView), "", "");
|
||||
@ -450,6 +450,66 @@ void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state
|
||||
gtk_stack_set_visible_child(GTK_STACK(mainWindow->stackRenderMode),
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -495,6 +555,9 @@ struct mainWindow *mainWindow_new()
|
||||
mainWindow->workspaceListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder,
|
||||
"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_end = -1;
|
||||
mainWindow->filterSettings.hide_all = TRUE;
|
||||
@ -506,6 +569,7 @@ struct mainWindow *mainWindow_new()
|
||||
g_object_unref(G_OBJECT(builder));
|
||||
|
||||
mainWindow_configure_treeView(mainWindow);
|
||||
mainWindow_configure_settings_dialog(mainWindow);
|
||||
mainWindow->webkitView = NULL;
|
||||
mainWindow->webkitScrollArea = NULL;
|
||||
mainWindow_connect_signals(mainWindow);
|
||||
@ -515,7 +579,7 @@ struct mainWindow *mainWindow_new()
|
||||
mainWindow_configure_entry_completion(mainWindow);
|
||||
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
|
||||
|
||||
mainWindow_webkit_set_enabled(mainWindow, TRUE);
|
||||
mainWindow_renderer_set(mainWindow, RENDERER_HTML);
|
||||
|
||||
return mainWindow;
|
||||
}
|
||||
@ -601,11 +665,12 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
|
||||
gchar *cmd_stderr = NULL;
|
||||
gint exit_status = 0;
|
||||
gchar *base_url = NULL;
|
||||
GFileOutputStream *stream;
|
||||
GFile *file;
|
||||
GFileOutputStream *stream = NULL;
|
||||
GFile *file = NULL;
|
||||
|
||||
if (mainWindow->webkitView &&
|
||||
gtk_stack_get_visible_child(GTK_STACK(mainWindow->stackRenderMode)) == mainWindow->webkitScrollArea) {
|
||||
if (mainWindow->renderer == RENDERER_TEXT) {
|
||||
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
|
||||
} else {
|
||||
if (text[0] != '\0') {
|
||||
base_url = g_strdup_printf("file://%s", file_url);
|
||||
file = g_file_new_for_path(tempfile_path);
|
||||
@ -619,12 +684,28 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
|
||||
cmd = g_strdup_printf("markdown %s", tempfile_path);
|
||||
if (g_spawn_command_line_sync(cmd, &cmd_stdout, &cmd_stderr, &exit_status, NULL) &&
|
||||
exit_status == 0) {
|
||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||
cmd_stdout, base_url);
|
||||
if (mainWindow->renderer == RENDERER_BASIC) {
|
||||
/* TODO: This renderer is broken. Pango does not like HTML... */
|
||||
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 {
|
||||
g_warning("Could not render markdown for file. Showing plain text instead.\n");
|
||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||
text, base_url);
|
||||
if (mainWindow->renderer == RENDERER_BASIC) {
|
||||
gtk_text_buffer_set_text(mainWindow->textBuffer,
|
||||
cmd_stdout, strlen(cmd_stdout));
|
||||
} else {
|
||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||
text, base_url);
|
||||
}
|
||||
}
|
||||
g_free(base_url);
|
||||
} else {
|
||||
@ -632,15 +713,17 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
|
||||
text, "");
|
||||
}
|
||||
|
||||
g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
|
||||
g_file_delete(file, NULL, NULL);
|
||||
g_object_unref(stream);
|
||||
g_object_unref(file);
|
||||
if (stream) {
|
||||
g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
|
||||
g_object_unref(stream);
|
||||
}
|
||||
if (file) {
|
||||
g_file_delete(file, NULL, NULL);
|
||||
g_object_unref(file);
|
||||
}
|
||||
g_free(cmd);
|
||||
g_free(cmd_stdout);
|
||||
g_free(cmd_stderr);
|
||||
} else {
|
||||
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,12 @@ enum {
|
||||
WSCOL_COUNT
|
||||
};
|
||||
|
||||
enum renderer_mode {
|
||||
RENDERER_TEXT = 0,
|
||||
RENDERER_BASIC,
|
||||
RENDERER_HTML
|
||||
};
|
||||
|
||||
struct mainWindow {
|
||||
GtkWidget *mainWindow;
|
||||
GtkWidget *mainPane;
|
||||
@ -47,6 +53,8 @@ struct mainWindow {
|
||||
GtkWidget *selectedDateEntry;
|
||||
GtkTreeModelFilter *entryListFiltered;
|
||||
|
||||
enum renderer_mode renderer;
|
||||
|
||||
gint64 time_earliest;
|
||||
gint64 time_latest;
|
||||
|
||||
@ -67,6 +75,11 @@ struct mainWindow {
|
||||
GtkTreeSelection *workspaceListSelection;
|
||||
GtkListStore *workspaceListStore;
|
||||
GtkTreeModelFilter *workspaceListFiltered;
|
||||
|
||||
struct settingsDialog {
|
||||
GtkWidget *settingsDialog;
|
||||
GtkWidget *comboDisplayMode;
|
||||
} settingsDialog;
|
||||
};
|
||||
|
||||
struct mainWindow *mainWindow_new();
|
||||
@ -90,6 +103,7 @@ 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_switch_workspace(struct mainWindow *mainWindow, gchar *path, gboolean gpg_enabled);
|
||||
void mainWindow_decrypt_gpg_clicked(GtkWidget *widget, gpointer user_data);
|
||||
void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state);
|
||||
void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode state);
|
||||
void mainWindow_settings_show(struct mainWindow *mainWindow);
|
||||
|
||||
#endif /* MAINWINDOW_H */
|
||||
|
Loading…
Reference in New Issue
Block a user