X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-text-file.c;h=e9aa8a3b1603bf4f252ca6e4932f6cf3a23fef41;hb=685be7e2f49916d06005ba8588dcf9d0be896aac;hp=9030896638d2ef2358a37626a36c7acb291353c4;hpb=50feac63e2fb9776f53e432f137311b4f5563ccf;p=pspp diff --git a/src/ui/gui/psppire-text-file.c b/src/ui/gui/psppire-text-file.c index 9030896638..e9aa8a3b16 100644 --- a/src/ui/gui/psppire-text-file.c +++ b/src/ui/gui/psppire-text-file.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2017 Free Software Foundation + Copyright (C) 2017, 2020 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -36,12 +36,13 @@ enum { PROP_0, PROP_FILE_NAME, - PROP_ENCODING + PROP_ENCODING, + PROP_MAXIMUM_LINES, + PROP_LINE_COUNT }; enum {MAX_LINE_LEN = 16384}; /* Max length of an acceptable line. */ - static void read_lines (PsppireTextFile *tf) { @@ -76,7 +77,7 @@ read_lines (PsppireTextFile *tf) tf->file_name, MAX_LINE_LEN); line_reader_close (reader); for (i = 0; i < tf->line_cnt; i++) - g_free (&tf->lines[i]); + g_free (tf->lines[i].string); tf->line_cnt = 0; ds_destroy (&input); return; @@ -86,7 +87,7 @@ read_lines (PsppireTextFile *tf) = recode_substring_pool ("UTF-8", line_reader_get_encoding (reader), input.ss, NULL); - } + } ds_destroy (&input); if (tf->line_cnt == 0) @@ -95,7 +96,7 @@ read_lines (PsppireTextFile *tf) msg (ME, _("`%s' is empty."), tf->file_name); line_reader_close (reader); for (i = 0; i < tf->line_cnt; i++) - g_free (&tf->lines[i]); + g_free (tf->lines[i].string); tf->line_cnt = 0; goto done; } @@ -124,7 +125,6 @@ read_lines (PsppireTextFile *tf) done: line_reader_close (reader); } - } static void @@ -137,6 +137,9 @@ psppire_text_file_set_property (GObject *object, switch (prop_id) { + case PROP_MAXIMUM_LINES: + tf->maximum_lines = g_value_get_int (value); + break; case PROP_FILE_NAME: tf->file_name = g_value_dup_string (value); read_lines (tf); @@ -163,6 +166,12 @@ psppire_text_file_get_property (GObject *object, switch (prop_id) { + case PROP_MAXIMUM_LINES: + g_value_set_int (value, text_file->maximum_lines); + break; + case PROP_LINE_COUNT: + g_value_set_int (value, text_file->line_cnt); + break; case PROP_FILE_NAME: g_value_set_string (value, text_file->file_name); break; @@ -184,7 +193,6 @@ static void psppire_text_file_dispose (GObject *object); static GObjectClass *parent_class = NULL; - static gboolean __tree_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter, @@ -295,7 +303,6 @@ __tree_model_get_flags (GtkTreeModel *model) static gint __tree_model_get_n_columns (GtkTreeModel *tree_model) { - PsppireTextFile *tf = PSPPIRE_TEXT_FILE (tree_model); return 2; } @@ -426,6 +433,20 @@ psppire_text_file_class_init (PsppireTextFileClass *class) parent_class = g_type_class_peek_parent (class); object_class = (GObjectClass*) class; + GParamSpec *maximum_lines_spec = + g_param_spec_int ("maximum-lines", + "Maximum Lines", + P_("An upper limit on the number of lines to consider"), + 0, G_MAXINT, G_MAXINT, + G_PARAM_READWRITE); + + GParamSpec *line_count_spec = + g_param_spec_int ("line-count", + "Line Count", + P_("The number of lines in the file"), + 0, G_MAXINT, G_MAXINT, + G_PARAM_READABLE); + GParamSpec *file_name_spec = g_param_spec_string ("file-name", "File Name", @@ -443,6 +464,14 @@ psppire_text_file_class_init (PsppireTextFileClass *class) object_class->set_property = psppire_text_file_set_property; object_class->get_property = psppire_text_file_get_property; + g_object_class_install_property (object_class, + PROP_MAXIMUM_LINES, + maximum_lines_spec); + + g_object_class_install_property (object_class, + PROP_LINE_COUNT, + line_count_spec); + g_object_class_install_property (object_class, PROP_FILE_NAME, file_name_spec); @@ -455,7 +484,6 @@ psppire_text_file_class_init (PsppireTextFileClass *class) object_class->dispose = psppire_text_file_dispose; } - static void psppire_text_file_init (PsppireTextFile *text_file) { @@ -484,6 +512,9 @@ psppire_text_file_finalize (GObject *object) { PsppireTextFile *tf = PSPPIRE_TEXT_FILE (object); + for (int i = 0; i < tf->line_cnt; i++) + g_free (tf->lines[i].string); + g_free (tf->encoding); g_free (tf->file_name);