root/todo/trunk/src/TodoDB.h

Revision 462, 3.8 kB (checked in by athomas, 1 year ago)

Dev Todo: Fixed #32, #29. Thanks!

Line 
1 #ifndef TODODB_H__
2 #define TODODB_H__
3
4 #include <stdexcept>
5 #include <vector>
6 #include <string>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <unistd.h>
10 #include "Todo.h"
11 #include "XML.h"
12 #include "Terminal.h"
13
14 using namespace std;
15
16 class Options;
17
18 /*
19         TodoDB is the workhorse of the program. It does all of the loading
20         and manipulating of the database.
21
22         01/02/01        Initial creation
23 */
24
25 class TodoDB {
26         public :
27                 class exception : public runtime_error { public : exception(string const &what) : runtime_error(what.c_str()) {} };
28                 class quit : public runtime_error { public : quit() : runtime_error("quit") {} };
29
30                 enum Mode {
31                         Add,
32                         Link,
33                         Remove,
34                         View,
35                         Edit,
36                         Generate,
37                         Done,
38                         NotDone,
39                         Title,
40                         Reparent,
41                         Stats,
42                         Purge,
43                 };
44
45                 TodoDB();
46                 TodoDB(string const &file);
47                 ~TodoDB();
48
49                 void load(string const &file = ".todo");
50                 void save(string const &file = ".todo");
51
52                 void operator () (Mode mode);
53
54                 Todo *find(string const &index) { return find(todo, index); }
55                 void erase(string &index) { return erase(todo, index); }
56
57                 vector<string> getIndexList(string const &indexList);
58
59                 void setColour(string const &item, string const &colour);
60
61                 void setDirty(bool d) { dirty = d; }
62                 bool isDirty() const { return dirty; }
63
64                 void triggerEvent(string const &event);
65
66                 multiset<Todo> todo;
67                 string titleText;
68                 string filename, basepath;
69
70         private :
71                 enum FilterChildren { FILTERED, NOTFILTERED, CHILDRENNOTFILTERED };
72
73                 void add();
74                 void link();
75                 void remove();
76                 void view();
77                 void edit();
78                 void generate();
79                 void done();
80                 void notdone();
81                 void edittitle();
82                 void reparent();
83                 void stats();
84                 void purge();
85
86                 // different loaders
87
88                 // Private, so object can't be default copied.
89                 TodoDB(TodoDB const &copy) {}
90                 TodoDB &operator = (TodoDB const &copy) { return *this; }
91
92                 Todo *find(multiset<Todo> const &todo, string const &index);
93                 multiset<Todo> &findContainer(multiset<Todo> &todo, string const &index);
94                 void erase(multiset<Todo> &todo, string const &index);
95                 void parse(vector<XML*>::const_iterator begin,
96                     vector<XML*>::const_iterator end, multiset<Todo> &out);
97                 void save(multiset<Todo> const &todo, ostream &of, int ind);
98                 void filterChildren(Todo &todo, FilterChildren filter = FILTERED);
99                 void filterView();
100                 void filterView(multiset<Todo> &todo);
101                 void stats(multiset<Todo> const &todo, int ind);
102                 void view(multiset<Todo> const &todo, int ind);
103                 void generate(ostream &out, multiset<Todo> const &todo, int ind);
104                 unsigned purge(multiset<Todo> &todo, time_t age);
105
106                 void fixParents(multiset<Todo> &todo, Todo *parent = 0);
107
108                 void initColour();
109                 void initColourPost();
110                 Todo::Priority getPriority(string current = "");
111                 int markDone(Todo &todo);
112                 int markNotDone(Todo &todo);
113
114                 void formatItem(ostream &out, int depth, Todo const &item, string const &format);
115
116                 string fixPath(string path);
117                 string fixRelativePath(string base, string path);
118
119                 struct stat _stat;
120                 bool statSuccessful;
121                 bool dirty;
122
123                 struct StreamColour {
124                         StreamColour() {}
125                         StreamColour(ostream &(*c)(ostream &), ostream &(*a)(ostream &)) : colour(c), attribute(a) {}
126                         ostream &(*colour)(ostream &);
127                         ostream &(*attribute)(ostream &);
128
129                         static ostream &veryhigh(ostream &os);
130                         static ostream &high(ostream &os);
131                         static ostream &medium(ostream &os);
132                         static ostream &low(ostream &os);
133                         static ostream &verylow(ostream &os);
134                         static ostream &info(ostream &os);
135                         static ostream &title(ostream &os);
136                         static ostream &comment(ostream &os);
137                         static ostream &mono(ostream &os);
138                         static ostream &normal(ostream &os);
139                 };
140                 static map<string, StreamColour> streamColour;
141
142                 // Colour strings
143                 ostream &(*priority[5])(ostream &);
144                 ostream &(*info)(ostream &);
145                 ostream &(*title)(ostream &);
146                 ostream &(*normal)(ostream &);
147                 ostream &(*comment)(ostream &);
148 };
149
150 #endif
Note: See TracBrowser for help on using the browser.