/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * e-table-specification.c * Copyright 2000, 2001, Ximian, Inc. * * Authors: * Chris Lahey * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License, version 2, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include #include "e-table-specification.h" #include #include #include #include #include #include "gal/util/e-util.h" #include "gal/util/e-xml-utils.h" #define PARENT_TYPE (gtk_object_get_type ()) static GtkObjectClass *etsp_parent_class; static void etsp_destroy (GtkObject *object) { ETableSpecification *etsp = E_TABLE_SPECIFICATION (object); int i; if (etsp->columns) { for (i = 0; etsp->columns[i]; i++) { gtk_object_unref (GTK_OBJECT (etsp->columns[i])); } g_free (etsp->columns); } if (etsp->state) gtk_object_unref (GTK_OBJECT (etsp->state)); g_free (etsp->click_to_add_message); etsp->columns = NULL; etsp->state = NULL; etsp->click_to_add_message = NULL; GTK_OBJECT_CLASS (etsp_parent_class)->destroy (object); } static void etsp_class_init (GtkObjectClass *klass) { etsp_parent_class = gtk_type_class (PARENT_TYPE); klass->destroy = etsp_destroy; } static void etsp_init (ETableSpecification *etsp) { etsp->columns = NULL; etsp->state = NULL; etsp->alternating_row_colors = TRUE; etsp->no_headers = FALSE; etsp->click_to_add = FALSE; etsp->click_to_add_end = FALSE; etsp->horizontal_draw_grid = FALSE; etsp->vertical_draw_grid = FALSE; etsp->draw_focus = TRUE; etsp->horizontal_scrolling = FALSE; etsp->allow_grouping = TRUE; etsp->cursor_mode = E_CURSOR_SIMPLE; etsp->selection_mode = GTK_SELECTION_MULTIPLE; etsp->click_to_add_message = NULL; } E_MAKE_TYPE (e_table_specification, "ETableSpecification", ETableSpecification, etsp_class_init, etsp_init, PARENT_TYPE); /** * e_table_specification_new: * * Creates a new %ETableSpecification object. This object is used to hold the * information about the rendering information for ETable. * * Returns: a newly created %ETableSpecification object. */ ETableSpecification * e_table_specification_new (void) { ETableSpecification *etsp = gtk_type_new (E_TABLE_SPECIFICATION_TYPE); return (ETableSpecification *) etsp; } /** * e_table_specification_load_from_file: * @specification: An ETableSpecification that you want to modify * @filename: a filename that contains an ETableSpecification * * This routine modifies @specification to reflect the state described * by the file @filename. * * Returns: TRUE on success, FALSE on failure. */ gboolean e_table_specification_load_from_file (ETableSpecification *specification, const char *filename) { xmlDoc *doc; doc = xmlParseFile (filename); if (doc) { xmlNode *node = xmlDocGetRootElement (doc); e_table_specification_load_from_node (specification, node); xmlFreeDoc (doc); return TRUE; } return FALSE; } /** * e_table_specification_load_from_string: * @specification: An ETableSpecification that you want to modify * @xml: a stringified representation of an ETableSpecification description. * * This routine modifies @specification to reflect the state described * by @xml. @xml is typically returned by e_table_specification_save_to_string * or it can be embedded in your source code. * * Returns: TRUE on success, FALSE on failure. */ gboolean e_table_specification_load_from_string (ETableSpecification *specification, const char *xml) { xmlDoc *doc; doc = xmlParseMemory ( (char *) xml, strlen (xml)); if (doc) { xmlNode *node = xmlDocGetRootElement (doc); e_table_specification_load_from_node (specification, node); xmlFreeDoc (doc); return TRUE; } return FALSE; } /** * e_table_specification_load_from_node: * @specification: An ETableSpecification that you want to modify * @node: an xmlNode with an XML ETableSpecification description. * * This routine modifies @specification to reflect the state described * by @node. */ void e_table_specification_load_from_node (ETableSpecification *specification, const xmlNode *node) { char *temp; xmlNode *children; GList *list = NULL, *list2; int i; specification->no_headers = e_xml_get_bool_prop_by_name (node, "no-headers"); specification->click_to_add = e_xml_get_bool_prop_by_name (node, "click-to-add"); specification->click_to_add_end = e_xml_get_bool_prop_by_name (node, "click-to-add-end") && specification->click_to_add; specification->alternating_row_colors = e_xml_get_bool_prop_by_name_with_default (node, "alternating-row-colors", TRUE); specification->horizontal_draw_grid = e_xml_get_bool_prop_by_name (node, "horizontal-draw-grid"); specification->vertical_draw_grid = e_xml_get_bool_prop_by_name (node, "vertical-draw-grid"); if (e_xml_get_bool_prop_by_name_with_default(node, "draw-grid", TRUE) == e_xml_get_bool_prop_by_name_with_default(node, "draw-grid", FALSE)) { specification->horizontal_draw_grid = specification->vertical_draw_grid = e_xml_get_bool_prop_by_name (node, "draw-grid"); } specification->draw_focus = e_xml_get_bool_prop_by_name_with_default (node, "draw-focus", TRUE); specification->horizontal_scrolling = e_xml_get_bool_prop_by_name_with_default (node, "horizontal-scrolling", FALSE); specification->allow_grouping = e_xml_get_bool_prop_by_name_with_default (node, "allow-grouping", TRUE); specification->selection_mode = GTK_SELECTION_MULTIPLE; temp = e_xml_get_string_prop_by_name (node, "selection-mode"); if (temp && !g_strcasecmp (temp, "single")) { specification->selection_mode = GTK_SELECTION_SINGLE; } else if (temp && !g_strcasecmp (temp, "browse")) { specification->selection_mode = GTK_SELECTION_BROWSE; } else if (temp && !g_strcasecmp (temp, "extended")) { specification->selection_mode = GTK_SELECTION_EXTENDED; } g_free (temp); specification->cursor_mode = E_CURSOR_SIMPLE; temp = e_xml_get_string_prop_by_name (node, "cursor-mode"); if (temp && !g_strcasecmp (temp, "line")) { specification->cursor_mode = E_CURSOR_LINE; } else if (temp && !g_strcasecmp (temp, "spreadsheet")) { specification->cursor_mode = E_CURSOR_SPREADSHEET; } g_free (temp); g_free (specification->click_to_add_message); specification->click_to_add_message = e_xml_get_string_prop_by_name ( node, "_click-to-add-message"); if (specification->state) gtk_object_unref (GTK_OBJECT (specification->state)); specification->state = NULL; if (specification->columns) { for (i = 0; specification->columns[i]; i++) { gtk_object_unref (GTK_OBJECT (specification->columns[i])); } g_free (specification->columns); } specification->columns = NULL; for (children = node->xmlChildrenNode; children; children = children->next) { if (!strcmp (children->name, "ETableColumn")) { ETableColumnSpecification *col_spec = e_table_column_specification_new (); e_table_column_specification_load_from_node (col_spec, children); list = g_list_append (list, col_spec); } else if (specification->state == NULL && !strcmp (children->name, "ETableState")) { specification->state = e_table_state_new (); e_table_state_load_from_node (specification->state, children); e_table_sort_info_set_can_group (specification->state->sort_info, specification->allow_grouping); } } specification->columns = g_new (ETableColumnSpecification *, g_list_length (list) + 1); for (list2 = list, i = 0; list2; list2 = g_list_next (list2), i++) { specification->columns[i] = list2->data; } specification->columns[i] = NULL; g_list_free (list); } /** * e_table_specification_save_to_file: * @specification: An %ETableSpecification that you want to save * @filename: a file name to store the specification. * * This routine stores the @specification into @filename. * * Returns: the number of bytes written or -1 on error. */ int e_table_specification_save_to_file (ETableSpecification *specification, const char *filename) { xmlDoc *doc; g_return_val_if_fail (specification != NULL, -1); g_return_val_if_fail (filename != NULL, -1); g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), -1); doc = xmlNewDoc ("1.0"); xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); return xmlSaveFile (filename, doc); } /** * e_table_specification_save_to_string: * @specification: An %ETableSpecification that you want to stringify * * Saves the state of @specification to a string. * * Returns: an g_alloc() allocated string containing the stringified * representation of @specification. This stringified representation * uses XML as a convenience. */ char * e_table_specification_save_to_string (ETableSpecification *specification) { char *ret_val; xmlChar *string; int length; xmlDoc *doc; g_return_val_if_fail (specification != NULL, NULL); g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL); doc = xmlNewDoc ("1.0"); xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); xmlDocDumpMemory (doc, &string, &length); ret_val = g_strdup (string); xmlFree (string); return ret_val; } /** * e_table_specification_save_to_node: * @specification: An ETableSpecification that you want to store. * @doc: Node where the specification is saved * * This routine saves the %ETableSpecification state in the object @specification * into the xmlDoc represented by @doc. * * Returns: The node that has been attached to @doc with the contents * of the ETableSpecification. */ xmlNode * e_table_specification_save_to_node (ETableSpecification *specification, xmlDoc *doc) { xmlNode *node; char *s; g_return_val_if_fail (doc != NULL, NULL); g_return_val_if_fail (specification != NULL, NULL); g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL); node = xmlNewNode (NULL, "ETableSpecification"); e_xml_set_bool_prop_by_name (node, "no-headers", specification->no_headers); e_xml_set_bool_prop_by_name (node, "click-to-add", specification->click_to_add); e_xml_set_bool_prop_by_name (node, "click-to-add-end", specification->click_to_add_end && specification->click_to_add); e_xml_set_bool_prop_by_name (node, "alternating-row-colors", specification->alternating_row_colors); e_xml_set_bool_prop_by_name (node, "horizontal-draw-grid", specification->horizontal_draw_grid); e_xml_set_bool_prop_by_name (node, "vertical-draw-grid", specification->vertical_draw_grid); e_xml_set_bool_prop_by_name (node, "draw-focus", specification->draw_focus); e_xml_set_bool_prop_by_name (node, "horizontal-scrolling", specification->horizontal_scrolling); e_xml_set_bool_prop_by_name (node, "allow-grouping", specification->allow_grouping); switch (specification->selection_mode){ case GTK_SELECTION_SINGLE: s = "single"; break; case GTK_SELECTION_BROWSE: s = "browse"; break; default: case GTK_SELECTION_EXTENDED: s = "extended"; } xmlSetProp (node, "selection-mode", s); if (specification->cursor_mode == E_CURSOR_LINE) s = "line"; else s = "cell"; xmlSetProp (node, "cursor-mode", s); xmlSetProp (node, "_click-to-add-message", specification->click_to_add_message); if (specification->columns){ int i; for (i = 0; specification->columns [i]; i++) e_table_column_specification_save_to_node ( specification->columns [i], node); } if (specification->state) e_table_state_save_to_node (specification->state, node); return node; } /** * e_table_specification_duplicate: * @spec: specification to duplicate * * This creates a copy of the %ETableSpecification @spec * * Returns: The duplicated %ETableSpecification. */ ETableSpecification * e_table_specification_duplicate (ETableSpecification *spec) { ETableSpecification *new_spec; char *spec_str; g_return_val_if_fail (spec != NULL, NULL); g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (spec), NULL); new_spec = e_table_specification_new (); spec_str = e_table_specification_save_to_string (spec); e_table_specification_load_from_string (new_spec, spec_str); g_free (spec_str); return new_spec; } >1-0/+1 * update math/R to 2.14.0, math/R-cran-sp to 0.9-91, and adjustbf2011-11-271-0/+1 * - Update to 7.0sunpoet2011-11-182-5/+5 * - Update to 7.0sunpoet2011-11-182-7/+6 * - Update to 7.0sunpoet2011-11-182-7/+6 * - Update to 7.0sunpoet2011-11-182-5/+5 * - Update to 7.0sunpoet2011-11-183-72/+78 * - Move PKGNAMEPREFIX defined in each R-cran- related ports Makefiletota2011-11-161-1/+0 * - Add PORTSCOUT knobsunpoet2011-11-161-0/+2 * Deprecate this port. Set for removal on 2011-12-11.rm2011-11-121-0/+3 * Mark as broken on powerpc: fails to link.linimon2011-11-111-0/+4 * - Remove WITH_FBSD10_FIX, is no longer neededmiwi2011-11-091-1/+0 * Remove ports@ ports that have been DEPRECATED for at least 1 monthdougb2011-11-025-145/+0 * Send ports@ ruby ports over ruby@pgollucci2011-11-021-1/+1 * - Update to 6.6sunpoet2011-11-012-4/+4 * Update poppler to 0.18.0.kwm2011-10-312-2/+16 * - Update to 6.0wen2011-10-312-7/+6 * - Fix build FreeBSD 10miwi2011-10-291-0/+1 * BSD licensed charset/encoding converter library with more function thanswills2011-10-285-0/+38 * - Update to 6.2sunpoet2011-10-272-7/+10 * - Update to 0.96-0tota2011-10-252-4/+3 * The vast majority of pkg-descr files had the following format when theydougb2011-10-242-2/+2 * - Return my ports back to the pool. I was unable to make any fixes tostas2011-10-241-1/+1 * - remove maintainer tags from pkg-descreadler2011-10-2313-41/+0 * - Add p5-Convert-NLS_DATE_FORMAT 0.03sunpoet2011-10-195-0/+33 * - Add LICENSEehaupt2011-10-182-17/+18 * - Add LICENSEehaupt2011-10-182-8/+9 * - Add LICENSEwen2011-10-172-31/+21 * update math/R to 2.13.2, and adjust dependent portsbf2011-10-111-0/+1 * - Fix LICENSE (Artistic 1 instead of Artistic 2)culot2011-10-072-4/+4 * - Update to r26711amdmi32011-09-263-90/+3 * remove unnecessary file.vanilla2011-09-251-21/+0 * - Use := in setting RUN_DEPENDS to quiet portlintswills2011-09-251-1/+3 * - Add LDFLAGS to CONFIGURE_ENV and MAKE_ENV (as it was done with LDFLAGS)amdmi32011-09-2411-22/+23 * - Rename bin/json_pp to bin/p5json_pp to avoid CONFLICTS with lang/perl5.14sunpoet2011-09-173-3/+31 * - Change PERL_CONFIGURE to "yes" for all values between 5.8.1+ and 5.8.9+sunpoet2011-09-171-1/+1 * - Change PERL_CONFIGURE to "yes" for all values less than or equal to 5.8.0+sunpoet2011-09-176-6/+6 * Change maintainer address to my FreeBSD addresscs2011-09-151-1/+1 * - Update to 0.95-0tota2011-09-062-3/+3 * - Add a new port: converters/R-cran-RJSONIOtota2011-09-044-0/+40 * - Deprecate this port because its functionality is integrated intoeadler2011-09-011-0/+3 * Remove myself from MAINTAINERache2011-08-301-1/+1 * Update to 0.05.tobez2011-08-262-3/+3 * - Fix MASTER_SITESmiwi2011-08-261-1/+1 * - Fix MASTER_SITESmiwi2011-08-261-1/+1 * Chase poppler shlib bumps.kwm2011-08-241-2/+2 * Turns out that some geocities sites are more dead than others.dougb2011-08-241-3/+0 * Geocities has been gone for almost 2 years now, so let's removedougb2011-08-231-0/+3 * - Add missing BUILD_DEPENDS to quiet build warningsswills2011-08-181-1/+2 * - Add missing BUILD_DEPENDSswills2011-08-181-1/+2 * Unbreak and bump PORTREVISION: rebuild cl-*-sbcl ports that dependolgeni2011-08-171-0/+1 * Bump PORTREVISION: rebuild ports that depend on devel/cl-asdf.olgeni2011-08-172-1/+2 * A JSON parsing and encoding library optimized for ease of use and highpgj2011-08-154-0/+30 * - Update to 2.32sunpoet2011-08-142-3/+3 * - Update to 2.44rafan2011-08-122-3/+3 * Remove USE_GNOME=gnometarget from ports. It has been a empty keyword sincekwm2011-08-121-1/+0 * Update to 1.4(0), unbreak.tobez2011-08-042-5/+5 * mark BROKEN: does not fetchbapt2011-08-031-0/+2 * Remove WWW entries from unmaintained ports that return 404 or where the domainehaupt2011-08-031-2/+0 * - Update to 1.10culot2011-08-012-3/+6 * Bye bye abandonwares (part 2)bapt2011-08-019-93/+0 * - Update to 2.31sunpoet2011-08-012-6/+4 * - Add notice about webfonts to pkg-descrmm2011-07-202-0/+7 * - Upgrade to 2.53.kuriyama2011-07-052-3/+3 * - Fix MASTER_SITESmiwi2011-07-022-4/+3 * - (Attempt to) fix after recent graphics/geos updateamdmi32011-06-302-0/+87 * Update to 1.4.8garga2011-06-302-4/+4 * Converts OSM planet.osm data to a PostgreSQL database suitableamdmi32011-06-295-0/+81 * - Chase converters/bsdconv shlib version bumpdhn2011-06-243-3/+6 * - Update to 6.0dhn2011-06-243-5/+9 * OpenStreetMap data into Polish map format (MP) convertoramdmi32011-06-226-0/+86 * - Replace ../../authors in MASTER_SITE_SUBDIR with CPAN:CPANID macro.az2011-06-213-3/+6 * - Replace ../../authors in MASTER_SITE_SUBDIR with CPAN:CPANID macro.az2011-06-201-1/+1 * Update converters/libticonv to 1.1.2 [1]jlaffaye2011-06-163-8/+6 * Another bunch of deprecation: no more public distfiles and/or abandonwarebapt2011-06-161-0/+3 * Another bunch of deprecation: no more public distfiles and/or abandonwarebapt2011-06-161-0/+3 * Unfetchable, no new home found: deprecatebapt2011-06-161-0/+3 * - Update to 5.1.1sunpoet2011-06-112-4/+4 * - Update to 1.29wen2011-06-082-3/+3 * - Update to 5.1sylvio2011-06-033-4/+8 * Bump PORTREVISION of all ports dependent on lang/ghc as duringashish2011-05-262-1/+2 * Update to 1.1.1.delphij2011-05-262-3/+3 * - Update bsdconv family to 5.0sunpoet2011-05-2512-78/+80 * - Update to 2.27200sunpoet2011-05-252-3/+3 * - Make portlint happiersunpoet2011-05-251-3/+4 * Remove zero-byte filesdougb2011-05-241-0/+0 * - Update 1.28sunpoet2011-05-132-3/+3 * - Update to 0.97culot2011-05-093-6/+10 * - Please welcome GHC 7.0.3ashish2011-05-095-68/+11 * - Update to 1.02amdmi32011-05-072-3/+3 * - Update to 4.6sunpoet2011-04-274-19/+29 * - Update to 4.8sunpoet2011-04-272-9/+14 * - Update to 4.8sunpoet2011-04-274-51/+69 * - Update to 2.27105sunpoet2011-04-262-3/+3 * - Fix PLISTsunpoet2011-04-171-1/+1 * - Use converters/bsdconv as master portsunpoet2011-04-166-27/+24 * - update to 0.76bapt2011-04-122-3/+6 * - update to 1.27bapt2011-04-112-3/+3 * - Update to 0.04.7culot2011-04-052-3/+3 * - update to 1.26bapt2011-04-012-3/+6 * - Update graphics/djvulibre* to 3.5.25. [1]stas2011-03-311-2/+2 * - Upgrade to 2.51.kuriyama2011-03-272-3/+3 * - Fix depends for option BUNDLED_LIBSmm2011-03-251-5/+1 * - Modify COMMENT and pkg-descr to provide a better description what thismm2011-03-222-5/+8 * - Remove empty line from pkg-messagemm2011-03-221-1/+0 * - Add LICENSE_FILE(s)mm2011-03-221-0/+3 * Add LICENSE informationmm2011-03-221-0/+3 * Simple shell utility to convert html to pdf using a custom static buildmm2011-03-226-0/+126 * - Get Rid MD5 supportmiwi2011-03-20111-114/+0 * PerlIO::via::Unidecode implements a PerlIO::via layer that appliesamdmi32011-03-125-0/+38 * Encode::Locale - Determine the locale encodingamdmi32011-03-125-0/+32 * - Add p5-JSON-PP 2.27104sunpoet2011-03-045-0/+38 * - Update to 2.42rafan2011-02-282-4/+4