Merge remote-tracking branch 'origin/master' into sheet
[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. */
61   struct substring lines[MAX_PREVIEW_LINES];
62   size_t line_cnt;
63   gulong total_lines; /* Number of lines in file. */
64   gboolean total_is_exact;    /* Is total_lines exact (or an estimate)? */
65
66   /*< private >*/
67   gboolean dispose_has_run ;
68   gint stamp;
69 };
70
71 struct _PsppireTextFileClass
72 {
73   GObjectClass parent_class;
74 };
75
76
77 typedef struct _PsppireTextFile       PsppireTextFile;
78 typedef struct _PsppireTextFileClass  PsppireTextFileClass;
79
80 GType psppire_text_file_get_type (void) G_GNUC_CONST;
81 PsppireTextFile *psppire_text_file_new (const gchar *file_name, const gchar *encoding);
82
83 gboolean psppire_text_file_get_total_exact (PsppireTextFile *tf);
84 gulong psppire_text_file_get_n_lines (PsppireTextFile *tf);
85
86 G_END_DECLS
87
88 #endif /* __PSPPIRE_TEXT_FILE_H__ */