예제 #1
0
파일: slib-editor.c 프로젝트: acli/xiphos
static void _load_file(EDITOR *e, const gchar *filename)
{
	//GtkWidget *choser;
	if (e->filename)
		g_free(e->filename);
	e->filename = g_strdup(filename);

	XI_message(("_load_file filename: %s", filename));

	xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
	settings.studypadfilename = xml_get_value("studypad", "lastfile");
	change_window_title(e->window, e->filename);

	char *contents;
	char *etag_out;
	gsize length;
	GFile *file;
	file = g_file_new_for_path(filename);
	gtkhtml_editor_set_filename(GTKHTML_EDITOR(e->window),
				    e->filename);
	if (g_file_load_contents(file, NULL, &contents, &length, &etag_out, NULL))
		gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window),
					     contents, length);
	gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
	gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE);
	return;
}
예제 #2
0
파일: slib-editor.c 프로젝트: acli/xiphos
void
editor_load_note(EDITOR *e, const gchar *module_name, const gchar *key)
{
	gchar *title;
	gchar *text;

	if (editor_is_dirty(e))
		_save_note(e);

	if (module_name) {
		if (e->module)
			g_free(e->module);
		e->module = g_strdup(module_name);
	}
	if (key) {
		if (e->key)
			g_free(e->key);
		e->key = g_strdup(key);
	}

	title = g_strdup_printf("%s - %s", e->module, e->key);
	text = main_get_raw_text((gchar *)e->module, (gchar *)e->key);
	if (strlen(text)) {
		gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window),
					     text, strlen(text));
		gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
		gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window),
					   FALSE);

	} else {
		gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window),
					     "", strlen(""));
		gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
		gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window),
					   FALSE);
	}

	change_window_title(e->window, title);
	if (e->type == NOTE_EDITOR)
		main_navbar_versekey_set(e->navbar, e->key);

	if (text)
		g_free(text);
	if (title)
		g_free(title);
}
예제 #3
0
파일: slib-editor.c 프로젝트: acli/xiphos
/* save if needed is done in treeky-editor.c before calling editor_load_book() */
void editor_load_book(EDITOR *e)
{
	gchar *title = NULL;
	gchar *text = NULL;

	if (!g_ascii_isdigit(e->key[0]))
		return; /* make sure is a number (offset) */

	title = g_strdup_printf("%s", e->module);
	XI_message(("book: %s\noffset :%s", e->module, e->key));

	if (atol(e->key) != 0)
		text = main_get_book_raw_text(e->module, e->key);
	else
		text = g_strdup(e->module);

	if (strlen(text)) {
		gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window),
					     text, strlen(text));
		gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
		gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window),
					   FALSE);
	} else {
		gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window),
					     "", strlen(""));
		gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
		gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window),
					   FALSE);
	}

	change_window_title(e->window, title);

	if (text)
		g_free(text);
	if (title)
		g_free(title);
}
예제 #4
0
파일: slib-editor.c 프로젝트: acli/xiphos
static void _save_book(EDITOR *e)
{
	GString *string;

	string = g_string_sized_new(4096);

	gtk_html_export(gtkhtml_editor_get_html(GTKHTML_EDITOR(e->window)),
			"text/html",
			(GtkHTMLSaveReceiverFn)_save_receiver, string);

	main_treekey_save_book_text(e->module, e->key, string->str);
	g_string_free(string, TRUE);
	gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
	gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE);
}
예제 #5
0
파일: slib-editor.c 프로젝트: acli/xiphos
static void action_new_cb(GtkAction *action, EDITOR *e)
{ /* for studypad only */

	if (editor_is_dirty(e))
		_save_file(e);

	_load_file(e,
		   g_strdup_printf("%s/%s", settings.gSwordDir,
				   "template.pad"));

	if (e->filename)
		g_free(e->filename);
	e->filename = g_strdup(_("Untitled document"));

	xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
	settings.studypadfilename = xml_get_value("studypad", "lastfile");
	change_window_title(e->window, e->filename);

	gtkhtml_editor_set_filename(GTKHTML_EDITOR(e->window), NULL);
	gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), TRUE);
}
예제 #6
0
파일: slib-editor.c 프로젝트: acli/xiphos
static void _save_file(EDITOR *e)
{
	const gchar *filename;
	gboolean as_html;
	GError *error = NULL;

	if (gtkhtml_editor_get_filename(GTKHTML_EDITOR(e->window)) == NULL)
		if (save_dialog(GTKHTML_EDITOR(e->window), e) ==
		    GTK_RESPONSE_CANCEL)
			return;

	filename = gtkhtml_editor_get_filename(GTKHTML_EDITOR(e->window));
	as_html = gtkhtml_editor_get_html_mode(GTKHTML_EDITOR(e->window));

	XI_message(("\n_save_file filename: %s\n", filename));

	gtkhtml_editor_save(GTKHTML_EDITOR(e->window), filename, as_html,
			    &error);
	handle_error(&error);

	gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
	gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE);
}
예제 #7
0
파일: slib-editor.c 프로젝트: acli/xiphos
GtkWidget *editor_new(const gchar *title, EDITOR *e)
{
	GtkActionGroup *action_group;
	GtkUIManager *manager;
	GtkWidget *editor;
	GError *error = NULL;

	editor = gtkhtml_editor_new();
	e->window = editor;
	e->html_widget =
	    GTK_WIDGET(gtkhtml_editor_get_html(GTKHTML_EDITOR(editor)));
	gtk_window_set_title(GTK_WINDOW(editor), title);

	set_window_icon(GTK_WINDOW(editor));

	manager = gtkhtml_editor_get_ui_manager(GTKHTML_EDITOR(editor));
	if (e->type == STUDYPAD_EDITOR)
		gtk_ui_manager_add_ui_from_string(manager, file_ui, -1,
						  &error);
	else
		gtk_ui_manager_add_ui_from_string(manager, note_file_ui,
						  -1, &error);

	handle_error(&error);

	gtk_ui_manager_add_ui_from_string(manager, view_ui, -1, &error);
	handle_error(&error);

	if (e->type == STUDYPAD_EDITOR)
		gtk_ui_manager_add_ui_from_string(manager,
						  main_ui_studypad, -1,
						  &error);
	else
		gtk_ui_manager_add_ui_from_string(manager, main_ui_note,
						  -1, &error);

	handle_error(&error);

	action_group = gtk_action_group_new("file");
	gtk_action_group_set_translation_domain(action_group,
						GETTEXT_PACKAGE);
	gtk_action_group_add_actions(action_group, file_entries,
				     G_N_ELEMENTS(file_entries), e);
	gtk_ui_manager_insert_action_group(manager, action_group, 0);

	action_group = gtk_action_group_new("view");
	gtk_action_group_set_translation_domain(action_group,
						GETTEXT_PACKAGE);
	gtk_action_group_add_actions(action_group, view_entries,
				     G_N_ELEMENTS(view_entries), editor);
	gtk_ui_manager_insert_action_group(manager, action_group, 0);

	action_group = gtk_action_group_new("main");
	gtk_action_group_set_translation_domain(action_group,
						GETTEXT_PACKAGE);
	gtk_action_group_add_actions(action_group, main_entries,
				     G_N_ELEMENTS(main_entries), e);
	gtk_ui_manager_insert_action_group(manager, action_group, 0);

	action_group = gtk_action_group_new("context-menu");
	gtk_action_group_set_translation_domain(action_group,
						GETTEXT_PACKAGE);
	gtk_action_group_add_actions(action_group, test_entries,
				     G_N_ELEMENTS(test_entries), e);
	gtk_ui_manager_insert_action_group(manager, action_group, 0);

	gtk_ui_manager_ensure_update(manager);
	gtk_widget_show(editor);

	gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
	gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE);

	g_signal_connect(editor, "delete-event",
			 G_CALLBACK(app_delete_cb), (EDITOR *)e);
	return editor;
}
예제 #8
0
gboolean
e_composer_autosave_snapshot (EMsgComposer *composer)
{
	GtkhtmlEditor *editor;
	CamelMimeMessage *message;
	AutosaveState *state;
	CamelStream *stream;
	gint camelfd;
	const gchar *errmsg;

	g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), FALSE);

	editor = GTKHTML_EDITOR (composer);

	/* If the contents are unchanged, exit early. */
	if (!gtkhtml_editor_get_changed (editor))
		return TRUE;

	state = g_object_get_data (G_OBJECT (composer), "autosave");
	g_return_val_if_fail (state != NULL, FALSE);

	/* Open the autosave file on-demand. */
	if (!composer_autosave_state_open (state, NULL)) {
		errmsg = _("Could not open autosave file");
		goto fail;
	}

	/* Extract a MIME message from the composer. */
	message = e_msg_composer_get_message_draft (composer);
	if (message == NULL) {
		errmsg = _("Unable to retrieve message from editor");
		goto fail;
	}

	/* Move to the beginning of the autosave file. */
	if (lseek (state->fd, (off_t) 0, SEEK_SET) < 0) {
		camel_object_unref (message);
		errmsg = g_strerror (errno);
		goto fail;
	}

	/* Destroy the contents of the autosave file. */
	if (ftruncate (state->fd, (off_t) 0) < 0) {
		camel_object_unref (message);
		errmsg = g_strerror (errno);
		goto fail;
	}

	/* Duplicate the file descriptor for Camel. */
	if ((camelfd = dup (state->fd)) < 0) {
		camel_object_unref (message);
		errmsg = g_strerror (errno);
		goto fail;
	}

	/* Open a CamelStream to the autosave file. */
	stream = camel_stream_fs_new_with_fd (camelfd);

	/* Write the message to the CamelStream. */
	if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream) < 0) {
		camel_object_unref (message);
		camel_object_unref (stream);
		errmsg = g_strerror (errno);
		goto fail;
	}

	/* Close the CamelStream. */
	if (camel_stream_close (CAMEL_STREAM (stream)) < 0) {
		camel_object_unref (message);
		camel_object_unref (stream);
		errmsg = g_strerror (errno);
		goto fail;
	}

	/* Snapshot was successful; set various flags. */
	gtkhtml_editor_set_changed (editor, FALSE);
	e_composer_autosave_set_saved (composer, TRUE);

	camel_object_unref (message);
	camel_object_unref (stream);

	return TRUE;

fail:
	e_error_run (
		GTK_WINDOW (composer), "mail-composer:no-autosave",
		(state->filename != NULL) ? state->filename : "",
		errmsg, NULL);

	return FALSE;
}