static InfSession* inf_test_gtk_browser_session_new(InfIo* io, InfConnectionManager* manager, InfConnectionManagerGroup* sync_group, InfXmlConnection* sync_connection, gpointer user_data) { InfTextGtkBuffer* buffer; InfUserTable* user_table; GtkTextBuffer* textbuffer; InfTextSession* session; textbuffer = gtk_text_buffer_new(NULL); user_table = inf_user_table_new(); buffer = inf_text_gtk_buffer_new(textbuffer, user_table); session = inf_text_session_new_with_user_table( manager, INF_TEXT_BUFFER(buffer), io, user_table, sync_group, sync_connection ); return INF_SESSION(session); }
static InfSession* infinoted_plugin_note_text_session_read(InfdStorage* storage, InfIo* io, InfCommunicationManager* manager, const gchar* path, gpointer user_data, GError** error) { InfUserTable* user_table; InfTextBuffer* buffer; gboolean result; InfTextSession* session; g_assert(INFD_IS_FILESYSTEM_STORAGE(storage)); user_table = inf_user_table_new(); buffer = INF_TEXT_BUFFER(inf_text_default_buffer_new("UTF-8")); result = inf_text_filesystem_format_read( INFD_FILESYSTEM_STORAGE(storage), path, user_table, buffer, error ); if(result == FALSE) { g_object_unref(user_table); g_object_unref(buffer); return NULL; } session = inf_text_session_new_with_user_table( manager, buffer, io, user_table, INF_SESSION_RUNNING, NULL, NULL ); g_object_unref(user_table); g_object_unref(buffer); return INF_SESSION(session); }
void Gobby::OperationOpen::read_finish() { // If the last character is a newline character, remove it. GtkTextIter end_iter, test_iter; gtk_text_buffer_get_end_iter(m_content, &end_iter); test_iter = end_iter; if(gtk_text_iter_backward_char(&test_iter)) { if(gtk_text_iter_get_char(&test_iter) == '\n') { gtk_text_buffer_delete( m_content, &test_iter, &end_iter); } } gtk_text_buffer_set_modified(m_content, FALSE); GtkTextIter insert_iter; GtkTextMark* insert = gtk_text_buffer_get_insert(m_content); gtk_text_buffer_get_iter_at_mark(m_content, &insert_iter, insert); InfUser* user = INF_USER(g_object_new( INF_TEXT_TYPE_USER, "id", 1, "flags", INF_USER_LOCAL, "name", m_preferences.user.name.get().c_str(), /* The user is made active when the user * switches to the document. */ "status", INF_USER_INACTIVE, "hue", m_preferences.user.hue.get(), "caret-position", gtk_text_iter_get_offset(&insert_iter), static_cast<void*>(NULL))); InfUserTable* user_table = inf_user_table_new(); inf_user_table_add_user(user_table, user); g_object_unref(user); InfTextGtkBuffer* text_gtk_buffer = inf_text_gtk_buffer_new(m_content, user_table); g_object_unref(user_table); ConnectionManager& connection_manager = get_browser().get_connection_manager(); InfCommunicationManager* communication_manager = connection_manager.get_communication_manager(); InfBrowser* browser = m_parent.get_browser(); InfIo* io; g_object_get(G_OBJECT(browser), "io", &io, NULL); InfTextSession* session = inf_text_session_new_with_user_table( communication_manager, INF_TEXT_BUFFER(text_gtk_buffer), io, user_table, INF_SESSION_RUNNING, NULL, NULL); g_object_unref(io); g_object_unref(text_gtk_buffer); InfRequest* request = inf_browser_add_note( m_parent.get_browser(), m_parent.get_browser_iter(), m_name.c_str(), "InfText", NULL, INF_SESSION(session), TRUE, on_request_finished_static, this); g_object_unref(session); if(request != NULL) { m_request = request; g_object_ref(m_request); // TODO: We can remove the node watch here, but need to have // the browser available in on_request_finished then. Maybe // just disconnect the signal, or bind it. } }
static InfSession* infd_note_plugin_text_session_read(InfdStorage* storage, InfIo* io, InfCommunicationManager* manager, const gchar* path, gpointer user_data, GError** error) { InfUserTable* user_table; InfTextBuffer* buffer; InfTextSession* session; FILE* stream; xmlDocPtr doc; xmlErrorPtr xmlerror; xmlNodePtr root; xmlNodePtr child; gboolean result; g_assert(INFD_IS_FILESYSTEM_STORAGE(storage)); user_table = inf_user_table_new(); buffer = INF_TEXT_BUFFER(inf_text_default_buffer_new("UTF-8")); /* TODO: Use a SAX parser for better performance */ stream = infd_filesystem_storage_open( INFD_FILESYSTEM_STORAGE(storage), "InfText", path, "r", error ); if(stream == NULL) return FALSE; doc = xmlReadIO( infd_note_plugin_text_session_read_read_func, infd_note_plugin_text_sesison_read_close_func, stream, path, /* TODO: Get some "infinote-filesystem-storage://" URL? */ "UTF-8", XML_PARSE_NOWARNING | XML_PARSE_NOERROR ); if(doc == NULL) { xmlerror = xmlGetLastError(); g_set_error( error, g_quark_from_static_string("LIBXML2_PARSER_ERROR"), xmlerror->code, "Error parsing XML in file '%s': [%d]: %s", path, xmlerror->line, xmlerror->message ); result = FALSE; } else { root = xmlDocGetRootElement(doc); if(strcmp((const char*)root->name, "inf-text-session") != 0) { g_set_error( error, g_quark_from_static_string("INF_NOTE_PLUGIN_TEXT_ERROR"), INFD_NOTE_PLUGIN_TEXT_ERROR_NOT_A_TEXT_SESSION, "Error processing file '%s': %s", path, "The document is not a text session" ); result = FALSE; } else { for(child = root->children; child != NULL; child = child->next) { if(child->type != XML_ELEMENT_NODE) continue; if(strcmp((const char*)child->name, "user") == 0) { if(!infd_note_plugin_text_read_user(user_table, child, error)) { g_prefix_error(error, "Error processing file '%s': ", path); result = FALSE; break; } } else if(strcmp((const char*)child->name, "buffer") == 0) { if(!infd_note_plugin_text_read_buffer(buffer, user_table, child, error)) { g_prefix_error(error, "Error processing file '%s': ", path); result = FALSE; break; } } else { infd_note_plugin_text_session_unexpected_node(child, error); g_prefix_error(error, "Error processing file '%s': ", path); result = FALSE; break; } } if(child == NULL) result = TRUE; } xmlFreeDoc(doc); } if(result == FALSE) return NULL; session = inf_text_session_new_with_user_table( manager, buffer, io, user_table, INF_SESSION_RUNNING, NULL, NULL ); return INF_SESSION(session); }