1 /***************************************************************************
2  *                                                                         *
3  *   Copyright : (C) 2010 The University of Toronto                        *
4  *   email     : netterfield@astro.utoronto.ca                             *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  ***************************************************************************/
12 
13 #ifndef KST_ASCII_SOURCE_CONFIG_H
14 #define KST_ASCII_SOURCE_CONFIG_H
15 
16 #include "namedparameter.h"
17 
18 #include <QDomElement>
19 #include <QDateTime>
20 
21 
22 class AsciiSourceConfig {
23 
24     // TODO translate keys?
25     static const char Key_fileNamePattern[];
26     static const char Tag_fileNamePattern[];
27     static const char Key_delimiters[];
28     static const char Tag_delimiters[];
29     static const char Key_indexVector[];
30     static const char Tag_indexVector[];
31     static const char Key_indexInterpretation[];
32     static const char Tag_indexInterpretation[];
33     static const char Key_timeAsciiFormatString[];
34     static const char Tag_timeAsciiFormatString[];
35     static const char Key_columnType[];
36     static const char Tag_columnType[];
37     static const char Key_columnDelimiter[];
38     static const char Tag_columnDelimiter[];
39     static const char Key_columnWidth[];
40     static const char Tag_columnWidth[];
41     static const char Key_columnWidthIsConst[];
42     static const char Tag_columnWidthIsConst[];
43     static const char Key_dataLine[];
44     static const char Tag_dataLine[];
45     static const char Key_readFields[];
46     static const char Tag_readFields[];
47     static const char Key_readUnits[];
48     static const char Tag_readUnits[];
49     static const char Key_useDot[];
50     static const char Tag_useDot[];
51     static const char Key_fieldsLine[];
52     static const char Tag_fieldsLine[];
53     static const char Key_unitsLine[];
54     static const char Tag_unitsLine[];
55     static const char Key_limitFileBuffer[];
56     static const char Tag_limitFileBuffer[];
57     static const char Key_limitFileBufferSize[];
58     static const char Tag_limitFileBufferSize[];
59     static const char Key_useThreads[];
60     static const char Tag_useThreads[];
61     static const char Key_dataRate[];
62     static const char Tag_dataRate[];
63     static const char Key_offsetDateTime[];
64     static const char Tag_offsetDateTime[];
65     static const char Key_offsetFileDate[];
66     static const char Tag_offsetFileDate[];
67     static const char Key_offsetRelative[];
68     static const char Tag_offsetRelative[];
69     static const char Key_dateTimeOffset[];
70     static const char Tag_dateTimeOffset[];
71     static const char Key_relativeOffset[];
72     static const char Tag_relativeOffset[];
73     static const char Key_nanValue[];
74     static const char Tag_nanValue[];
75     static const char Key_updateType[];
76     static const char Tag_updateType[];
77 
78   public:
79     AsciiSourceConfig();
80 
81     bool operator==(const AsciiSourceConfig&) const;
82     bool operator!=(const AsciiSourceConfig& rhs) const;
83     bool isUpdateNecessary(const AsciiSourceConfig& rhs) const;
84 
85     void saveDefault(QSettings& cfg) const;
86     void saveGroup(QSettings& cfg, const QString& fileName) const;
87     const AsciiSourceConfig& readGroup(QSettings& cfg, const QString& fileName = QString());
88 
89     void save(QXmlStreamWriter& s);
90     void parseProperties(QXmlStreamAttributes &properties);
91 
92     void load(const QDomElement& e);
93 
94     enum Interpretation { Unknown = 0, NoInterpretation, CTime, Seconds, FormattedTime, FixedRate, IntEnd = 0xffff };
95     enum ColumnType { Whitespace = 0, Fixed, Custom, ColEnd = 0xffff };
96 
97     NamedParameter<QString, Key_delimiters, Tag_delimiters> _delimiters;
98     NamedParameter<QString, Key_indexVector, Tag_indexVector> _indexVector;
99     NamedParameter<int, Key_indexInterpretation, Tag_indexInterpretation> _indexInterpretation;
100     NamedParameter<QString, Key_timeAsciiFormatString, Tag_timeAsciiFormatString> _timeAsciiFormatString;
101     NamedParameter<QString, Key_fileNamePattern, Tag_fileNamePattern> _fileNamePattern;
102     NamedParameter<int, Key_columnType, Tag_columnType> _columnType;
103     NamedParameter<QString, Key_columnDelimiter, Tag_columnDelimiter> _columnDelimiter;
104     NamedParameter<int, Key_columnWidth, Tag_columnWidth> _columnWidth;
105     NamedParameter<bool, Key_columnWidthIsConst, Tag_columnWidthIsConst> _columnWidthIsConst;
106     NamedParameter<int, Key_dataLine, Tag_dataLine> _dataLine;
107     NamedParameter<bool, Key_readFields, Tag_readFields> _readFields;
108     NamedParameter<bool, Key_readUnits, Tag_readUnits> _readUnits;
109     NamedParameter<int, Key_fieldsLine, Tag_fieldsLine> _fieldsLine;
110     NamedParameter<int, Key_unitsLine, Tag_unitsLine> _unitsLine;
111     NamedParameter<bool, Key_useDot, Tag_useDot> _useDot;
112     NamedParameter<bool, Key_limitFileBuffer, Tag_limitFileBuffer> _limitFileBuffer;
113     NamedParameter<qint64, Key_limitFileBufferSize, Tag_limitFileBufferSize> _limitFileBufferSize;
114     NamedParameter<int, Key_useThreads, Tag_useThreads> _useThreads;
115     NamedParameter<double, Key_dataRate, Tag_dataRate> _dataRate;
116     NamedParameter<bool, Key_offsetDateTime, Tag_offsetDateTime> _offsetDateTime;
117     NamedParameter<bool, Key_offsetFileDate, Tag_offsetFileDate> _offsetFileDate;
118     NamedParameter<bool, Key_offsetRelative, Tag_offsetRelative> _offsetRelative;
119     NamedParameter<QDateTime, Key_dateTimeOffset, Tag_dateTimeOffset> _dateTimeOffset;
120     NamedParameter<double, Key_relativeOffset, Tag_relativeOffset> _relativeOffset;
121     NamedParameter<int, Key_nanValue, Tag_nanValue> _nanValue;
122     NamedParameter<int, Key_updateType, Tag_updateType> _updateType;
123 
124   private:
125     void save(QSettings& cfg) const;
126     void read(QSettings& cfg);
127 };
128 
129 Q_DECLARE_METATYPE(AsciiSourceConfig::Interpretation)
130 Q_DECLARE_METATYPE(AsciiSourceConfig::ColumnType)
131 
132 #endif
133