500acc82bd0086d7d61b95f821d005df0d6b55f4
[pspp] / src / ui / gui / psppire-text-file.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2017  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef __PSPPIRE_TEXT_FILE_H__
18 #define __PSPPIRE_TEXT_FILE_H__
19
20 #include "libpspp/str.h"
21
22 #include <glib-object.h>
23
24 G_BEGIN_DECLS
25
26
27
28 #define PSPPIRE_TYPE_TEXT_FILE         (psppire_text_file_get_type ())
29
30 #define PSPPIRE_TEXT_FILE(obj)  \
31   (G_TYPE_CHECK_INSTANCE_CAST ((obj),                                   \
32                                PSPPIRE_TYPE_TEXT_FILE, PsppireTextFile))
33
34 #define PSPPIRE_TEXT_FILE_CLASS(klass) \
35   (G_TYPE_CHECK_CLASS_CAST ((klass),                                    \
36                             PSPPIRE_TYPE_TEXT_FILE,                    \
37                             PsppireTextFileClass))
38
39
40 #define PSPPIRE_IS_TEXT_FILE(obj) \
41   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_TEXT_FILE))
42
43 #define PSPPIRE_IS_TEXT_FILE_CLASS(klass) \
44   (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_TEXT_FILE))
45
46 #define PSPPIRE_TEXT_FILE_GET_CLASS(obj) \
47   (G_TYPE_INSTANCE_GET_CLASS ((obj),                                    \
48                               PSPPIRE_TYPE_TEXT_FILE,                  \
49                               PsppireTextFileClass))
50
51 enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */
52
53 struct _PsppireTextFile
54 {
55   GObject parent;
56
57   gchar *file_name;
58   gchar *encoding;
59
60   /* The first several lines of the file.   These copies which are UTF8 encoded,
61      regardless of the file encoding.  */
62   struct substring lines[MAX_PREVIEW_LINES];
63   size_t line_cnt;
64
65   gulong total_lines; /* Number of lines in file. */
66   gboolean total_is_exact;    /* Is total_lines exact (or an estimate)? */
67
68   /*< private >*/
69   gboolean dispose_has_run ;
70   gint stamp;
71 };
72
73 struct _PsppireTextFileClass
74 {
75   GObjectClass parent_class;
76 };
77
78
79 typedef struct _PsppireTextFile       PsppireTextFile;
80 typedef struct _PsppireTextFileClass  PsppireTextFileClass;
81
82 GType psppire_text_file_get_type (void) G_GNUC_CONST;
83 PsppireTextFile *psppire_text_file_new (const gchar *file_name, const gchar *encoding);
84
85 gboolean psppire_text_file_get_total_exact (PsppireTextFile *tf);
86 gulong psppire_text_file_get_n_lines (PsppireTextFile *tf);
87
88 G_END_DECLS
89
90 #endif /* __PSPPIRE_TEXT_FILE_H__ */