OSDN Git Service

d4cec25e116aa13acd8e22189f945e2217a5afa4
[tjqt4port/tj2qt4.git] / taskjuggler / ProjectFile.h
1 /*
2  * ProjectFile.h - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002 by Chris Schlaeger <cs@suse.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * $Id$
11  */
12
13 #ifndef _ProjectFile_h_
14 #define _ProjectFile_h_
15
16 #include <stdio.h>
17 #include <time.h>
18 #include <stdarg.h>
19
20 #include <qstring.h>
21 #include <qvaluelist.h>
22
23 #include "Project.h"
24 #include "Token.h"
25 #include "MacroTable.h"
26
27 class QTextStream;
28 class ProjectFile;
29 class Project;
30 class Operation;
31 class ReportHtml;
32
33 class FileInfo
34 {
35 public:
36         FileInfo(ProjectFile* p, const QString& file, const QString& tp);
37         ~FileInfo() { }
38
39         bool open();
40         bool close();
41
42         QChar getC(bool expandMacros = TRUE);
43         void ungetC(QChar c);
44         void expandMarco(QString& c);
45
46         const QString& getFile() const { return file; }
47         QString getPath() const;
48
49         int getLine() const { return currLine; }
50
51         TokenType nextToken(QString& buf);
52         void returnToken(TokenType t, const QString& buf);
53
54         bool readMacroCall();
55
56         const QString& getTaskPrefix() { return taskPrefix; }
57
58         void fatalErrorVA(const char* msg, va_list ap);
59         void fatalError(const char* msg, ...);
60
61 private:
62         bool getDateFragment(QString& token, QChar& c);
63
64         /**
65          * A pointer to the ProjectFile class that stores all read-in
66          * data.
67          */
68         ProjectFile* pf;
69         
70         // The name of the file.
71         QString file;
72
73         // The file handle of the file to read.
74         FILE* fh;
75
76         // The stream used to read the file.
77         QTextStream* f;
78
79         // The number of the line currently being read.
80         int currLine;
81
82         /**
83          * Macros have file scope. So we keep a stack of macros for each file that
84          * we read.
85          */
86         QPtrList<Macro> macroStack;
87
88         /**
89          * A buffer for the part of the line that has been parsed already. This is
90          * primarily used for error reporting.
91          */
92         QString lineBuf;
93
94         /**
95          * A buffer for characters that have been pushed back again. This
96          * simplifies file parsing in some situations.
97          */
98         QValueList<QChar> ungetBuf;
99
100         /**
101      * Besides read in characters we can also push back a token. Contrary to
102          * characters we can push back only 1 token. This is stored as type and
103          * a string buffer.
104          */      
105         TokenType tokenTypeBuf;
106         QString tokenBuf;
107
108         /**
109          * Task trees of include files can not only be added at global scope but
110          * also as sub-trees. This strings stores the prefix that has to be
111          * specified at include times.
112          */
113         QString taskPrefix;
114 };
115
116 class ProjectFile
117 {
118 public:
119         ProjectFile(Project* p);
120         ~ProjectFile() { }
121
122         bool open(const QString& file, const QString& parentPath,
123                           const QString& taskPrefix);
124         bool close();
125         bool parse();
126         void setDebugLevel(int l) { debugLevel = l; }
127         void setDebugMode(int m) { debugMode = m; }
128         
129         TokenType nextToken(QString& token);
130         void returnToken(TokenType t, const QString& buf)
131         {
132                 if (!openFiles.isEmpty())
133                         openFiles.last()->returnToken(t, buf);
134         }
135
136         const QString& getFile()
137         {
138                 if (openFiles.isEmpty())
139                         return QString::null;
140                 return openFiles.last()->getFile(); 
141         }
142         int getLine()
143         {
144                 if (openFiles.isEmpty())
145                         return -1;
146                 return openFiles.last()->getLine(); 
147         }
148
149         bool moreFiles() { return !openFiles.isEmpty(); }
150
151         const QString& getTaskPrefix();
152
153         void fatalError(const char* msg, ...);
154
155         MacroTable& getMacros() { return macros; }
156
157 private:
158         ProjectFile() {};       // don't use
159
160         bool readProject();
161         bool readInclude();
162         bool readTask(Task* parent);
163         bool readTaskSupplement(QString prefix);
164         bool readTaskBody(Task* task);
165         bool readResource(Resource* parent);
166         bool readResourceSupplement();
167         bool readResourceBody(Resource* r);
168         bool readVacation(time_t& from, time_t& to, bool readName = FALSE,
169                                           QString* = 0);
170         bool readAccount(Account* parent);
171         bool readShift(Shift* parent);
172         Shift* readShiftSelection(time_t& from, time_t& to);
173         Booking* readBooking();
174         bool readCredit(Account* a);
175         bool readAllocate(Task* t);
176         bool readPlanTimeFrame(double& d, bool workingDays);
177         bool readTimeValue(ulong& value);
178         bool readPercent(double& value);
179         bool readWorkingHours(int& dayOfWeek, QPtrList<Interval>* l);
180         bool readPriority(int& priority);
181         bool checkReportInterval(ReportHtml* report);
182         bool readHTMLReport(const QString& reportType);
183         bool readHTMLAccountReport();
184         bool readExportReport();
185         bool readXMLReport();
186         bool readHtmlUrl(ReportHtml* report);
187 #ifdef HAVE_KDE
188         bool readICalTaskReport();
189 #endif
190         Operation* readLogicalExpression(int precedence = 0);
191         Operation* readFunctionCall(const QString& name);
192         bool readSorting(Report* report, int which);
193         time_t date2time(const QString& date);
194         int hhmm2time(const QString& hhmm);
195
196         QString masterFile;
197         Project* proj;
198         QList<FileInfo> openFiles;
199         QStringList includedFiles;
200         MacroTable macros;
201         static int debugLevel;
202         static int debugMode;
203 };
204
205 #endif