#ifndef TODODB_H__ #define TODODB_H__ #include #include #include #include #include #include #include "Todo.h" #include "XML.h" #include "Terminal.h" using namespace std; class Options; /* TodoDB is the workhorse of the program. It does all of the loading and manipulating of the database. 01/02/01 Initial creation */ class TodoDB { public : class exception : public runtime_error { public : exception(string const &what) : runtime_error(what.c_str()) {} }; class quit : public runtime_error { public : quit() : runtime_error("quit") {} }; enum Mode { Add, Link, Remove, View, Edit, Generate, Done, NotDone, Title, Reparent, Stats, Purge, }; TodoDB(); TodoDB(string const &file); ~TodoDB(); void load(string const &file = ".todo"); void save(string const &file = ".todo"); void operator () (Mode mode); Todo *find(string const &index) { return find(todo, index); } void erase(string &index) { return erase(todo, index); } vector getIndexList(string const &indexList); void setColour(string const &item, string const &colour); void setDirty(bool d) { dirty = d; } bool isDirty() const { return dirty; } void triggerEvent(string const &event); multiset todo; string titleText; string filename, basepath; private : enum FilterChildren { FILTERED, NOTFILTERED, CHILDRENNOTFILTERED }; void add(); void link(); void remove(); void view(); void edit(); void generate(); void done(); void notdone(); void edittitle(); void reparent(); void stats(); void purge(); // different loaders // Private, so object can't be default copied. TodoDB(TodoDB const ©) {} TodoDB &operator = (TodoDB const ©) { return *this; } Todo *find(multiset const &todo, string const &index); multiset &findContainer(multiset &todo, string const &index); void erase(multiset &todo, string const &index); void parse(vector::const_iterator begin, vector::const_iterator end, multiset &out); void save(multiset const &todo, ostream &of, int ind); void filterChildren(Todo &todo, FilterChildren filter = FILTERED); void filterView(); void filterView(multiset &todo); void stats(multiset const &todo, int ind); void view(multiset const &todo, int ind); void generate(ostream &out, multiset const &todo, int ind); unsigned purge(multiset &todo, time_t age); void fixParents(multiset &todo, Todo *parent = 0); void initColour(); void initColourPost(); Todo::Priority getPriority(string current = ""); int markDone(Todo &todo); int markNotDone(Todo &todo); void formatItem(ostream &out, int depth, Todo const &item, string const &format); string fixPath(string path); string fixRelativePath(string base, string path); struct stat _stat; bool statSuccessful; bool dirty; struct StreamColour { StreamColour() {} StreamColour(ostream &(*c)(ostream &), ostream &(*a)(ostream &)) : colour(c), attribute(a) {} ostream &(*colour)(ostream &); ostream &(*attribute)(ostream &); static ostream &veryhigh(ostream &os); static ostream &high(ostream &os); static ostream &medium(ostream &os); static ostream &low(ostream &os); static ostream &verylow(ostream &os); static ostream &info(ostream &os); static ostream &title(ostream &os); static ostream &comment(ostream &os); static ostream &mono(ostream &os); static ostream &normal(ostream &os); }; static map streamColour; // Colour strings ostream &(*priority[5])(ostream &); ostream &(*info)(ostream &); ostream &(*title)(ostream &); ostream &(*normal)(ostream &); ostream &(*comment)(ostream &); }; #endif