Added basic support for images
This commit is contained in:
parent
73868c81b0
commit
2d8d86781c
@ -240,6 +240,7 @@ static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
|
||||
G_TYPE_POINTER,
|
||||
G_TYPE_POINTER,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING);
|
||||
mainWindow->entryListFiltered = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(
|
||||
GTK_TREE_MODEL(mainWindow->entryListStore),
|
||||
@ -592,19 +593,21 @@ void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data)
|
||||
g_free(text);
|
||||
}
|
||||
|
||||
static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text)
|
||||
static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gchar *file_url)
|
||||
{
|
||||
gchar *tempfile_path = "/tmp/mdiary.tmp.md";
|
||||
gchar *cmd = NULL;
|
||||
gchar *cmd_stdout = NULL;
|
||||
gchar *cmd_stderr = NULL;
|
||||
gint exit_status = 0;
|
||||
gchar *base_url = NULL;
|
||||
GFileOutputStream *stream;
|
||||
GFile *file;
|
||||
|
||||
if (mainWindow->webkitView &&
|
||||
gtk_stack_get_visible_child(GTK_STACK(mainWindow->stackRenderMode)) == mainWindow->webkitScrollArea) {
|
||||
if (text[0] != '\0') {
|
||||
base_url = g_strdup_printf("file://%s", file_url);
|
||||
file = g_file_new_for_path(tempfile_path);
|
||||
stream = g_file_replace(
|
||||
file, NULL, FALSE,
|
||||
@ -617,12 +620,13 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text)
|
||||
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, "");
|
||||
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, "");
|
||||
}
|
||||
g_free(base_url);
|
||||
} else {
|
||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||
text, "");
|
||||
@ -651,6 +655,7 @@ void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data)
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
gchar *file_url;
|
||||
gchar *text;
|
||||
gchar *title;
|
||||
gchar *summary;
|
||||
@ -659,18 +664,21 @@ void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data)
|
||||
selection = gtk_tree_view_get_selection(mainWindow->entryListView);
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
||||
gtk_tree_model_get(model, &iter, COL_TEXT, &text, -1);
|
||||
mainWindow_set_text(mainWindow, text);
|
||||
gtk_tree_model_get(model, &iter, COL_URL, &file_url, -1);
|
||||
mainWindow_set_text(mainWindow, text, file_url);
|
||||
g_free(text);
|
||||
g_free(file_url);
|
||||
|
||||
gtk_tree_model_get(model, &iter, COL_SUMMARY, &summary, -1);
|
||||
gtk_tree_model_get(model, &iter, COL_TITLE, &title, -1);
|
||||
temp = g_strdup_printf("<b>%s</b>: %s", title, summary);
|
||||
gtk_label_set_markup(GTK_LABEL(mainWindow->labelSummary), temp);
|
||||
|
||||
g_free(title);
|
||||
g_free(summary);
|
||||
g_free(temp);
|
||||
} else {
|
||||
mainWindow_set_text(mainWindow, "");
|
||||
mainWindow_set_text(mainWindow, "", "");
|
||||
gtk_label_set_text(GTK_LABEL(mainWindow->labelSummary), "Please select an entry in the list above.");
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +346,8 @@ static void mdiary_add_file_to_store(struct mdiary_scanner *mdiary_scanner,
|
||||
datetime,
|
||||
tagList,
|
||||
summary,
|
||||
text->str);
|
||||
text->str,
|
||||
filename);
|
||||
|
||||
if (g_date_time_to_unix(datetime) > mdiary_scanner->time_latest)
|
||||
mdiary_scanner->time_latest = g_date_time_to_unix(datetime);
|
||||
@ -542,7 +543,8 @@ void mdiary_add_entry_to_store(GtkListStore *entryListStore,
|
||||
GDateTime *datetime,
|
||||
GList *tags,
|
||||
gchar *summary,
|
||||
gchar *text)
|
||||
gchar *text,
|
||||
gchar *file_url)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GDateTime *datetime_copy;
|
||||
@ -567,6 +569,7 @@ void mdiary_add_entry_to_store(GtkListStore *entryListStore,
|
||||
COL_TAGLIST, taglist_copy, /* TODO: Verify that the duplication worked! */
|
||||
COL_SUMMARY, summary, /* Automatically strdupd */
|
||||
COL_TEXT, text, /* Automatically strdupd */
|
||||
COL_URL, file_url, /* Automatically strdupd */
|
||||
-1);
|
||||
g_free(date_text);
|
||||
|
||||
|
@ -13,6 +13,7 @@ enum {
|
||||
COL_TAGLIST, /* GList<gchar *> of the tags */
|
||||
COL_SUMMARY, /* Summary of the entry */
|
||||
COL_TEXT, /* Raw text from the file */
|
||||
COL_URL, /* Path to the file */
|
||||
COL_COUNT
|
||||
};
|
||||
|
||||
@ -36,7 +37,8 @@ void mdiary_add_entry_to_store(GtkListStore *entryListStore,
|
||||
GDateTime *datetime,
|
||||
GList *tags,
|
||||
gchar *summary,
|
||||
gchar *text);
|
||||
gchar *text,
|
||||
gchar *file_url);
|
||||
GDateTime *mdiary_get_date_from_string_ext(gchar *string, gchar *prefix, gchar *suffix);
|
||||
GDateTime *mdiary_get_date_from_string(gchar *string);
|
||||
void mdiary_reset_store(GtkListStore *entryListStore, GtkListStore *autoCompletion);
|
||||
|
Loading…
Reference in New Issue
Block a user