comparison gui/src/qtinfo/parser.h @ 15055:48ae6a7c69c1 gui

Integrated texinfo browser from QtOctave. * documentation-dockwidget.cc: Added new dock widget for the documentation. * documentation-dockwidget.h: Added new dock widget for the documentation. * bookmark.png: New icon file. * question.png: New icon file. * star.png: New icon file. * stop.png: New icon file. * zoom-in.png: New icon file. * zoom-out.png: New icon file. * parser.cc: Added file from QtOctave, refactored code. * parser.h: Added file from QtOctave, refactored code. * webinfo.cc: Added file from QtOctave, refactored code. * webinfo.h: Added file from QtOctave, refactored code. * main-window.cc: Added menu entries to handle documentation and integrated new documentation dock widget. * main-window.h: Including header for documentation dock widget and added member variable. * resource.qrc: Added icon entries for new icon files. * src.pro: Added file entries for new file added to the project.
author Jacob Dawid <jacob.dawid@gmail.com>
date Mon, 30 Jul 2012 19:27:14 +0200
parents
children
comparison
equal deleted inserted replaced
15053:6889217b9d78 15055:48ae6a7c69c1
1 /* Copyright (C) 2009 P.L. Lucas
2 * Copyright (C) 2012 Jacob Dawid <jacob.dawid@gmail.com>
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 2 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, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 #include <QStringList>
21 #include <QIODevice>
22 #include <QFileInfoList>
23 #include <QHash>
24
25 /**
26 * \class parser
27 * This class gets nodes and searchs inside of `info files'.
28 * <p>Each info file has nodes. Every node has the documentation.
29 * Info files contains a map with position of each node.</p>
30 * <p>What is position?
31 * There is a simple answer:
32 * If you make a queue with info files, position will be the number of bytes
33 * from begining to node position.</p>
34 * <p>
35 * But is not so easy. There is headers, and qtinfo must not take these headers into account.
36 * </p>
37 * <p>
38 * This class also translates info files to html.
39 * </p>
40 */
41 class parser
42 : public QObject
43 {
44 Q_OBJECT
45
46 public:
47 parser (QObject *parent = 0);
48 void set_info_path (QString _info_path);
49 QString get_info_path ();
50 QString search_node (QString node);
51 QString global_search (QString text, int maxFounds);
52
53 /** Checks if this node is reference. If node is reference, it will be returned its position
54 * in text, else it will be returned -1.
55 */
56 int is_ref (QString node);
57
58 /**Translates text of node to Html. If anchorPos is not -1, then anchor is inserted in that
59 * position.
60 */
61 QString node_text_to_html (QString text, int anchorPos=-1, QString anchor=QString());
62
63 private:
64 struct node_position
65 {
66 QString _node_name;
67 int pos;
68 };
69
70 struct node_map_item
71 {
72 int pos;
73 };
74
75 struct info_file_item
76 {
77 QFileInfo file_info;
78 int real_size;
79 };
80
81 QString search_node (QString node, QIODevice * io);
82 QString get_next_node (QIODevice * io);
83 QString get_node_name (QString text);
84 QString get_node_up (QString text);
85 QString get_node_next (QString text);
86 QString get_node_prev (QString text);
87
88 /** Parses info files and gets map of node positions.*/
89 void parse_info_map();
90
91 /** Open info files and uncompress them. */
92 QIODevice *open_file(QFileInfo & fileInfo);
93
94 /** Calculates real position of nodes.
95 * \param pos position from info file.
96 * \param fileInfo returns file what contains that position.
97 * \param realPos returns real position inside of fileInfo.
98 */
99 void real_position (int pos, QFileInfo & file_info, int & real_pos);
100
101 /** Seeks to position pos. */
102 void seek (QIODevice *io, int pos);
103
104
105 QString _info_path;
106 QFileInfoList _info_files;
107 QHash<QString, node_map_item> _node_map;
108 QHash<QString, node_position> _ref_map;
109 QList<info_file_item> _info_file_real_size_list;
110 QHash<QString, QString> _compressors_map;
111 };