From d86b35487088ee31cfc86a7950580b87fc56e048 Mon Sep 17 00:00:00 2001 From: msharov Date: Tue, 11 Jul 2006 17:37:12 +0000 Subject: [PATCH] Initial revision --- Makefile | 9 +++++ tde.cc | 47 ++++++++++++++++++++++++++ tde.h | 42 +++++++++++++++++++++++ todo.cc | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 Makefile create mode 100644 tde.cc create mode 100644 tde.h create mode 100644 todo.cc diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..25460ae --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +include Config.mk + +EXE = todo +SRCS = $(wildcard *.cc) +OBJS = $(SRCS:.cc=.o) +LIBS = -lutio -lustl + +include Comrubin.mk + diff --git a/tde.cc b/tde.cc new file mode 100644 index 0000000..17bf044 --- /dev/null +++ b/tde.cc @@ -0,0 +1,47 @@ +// tde.cc +// + +#include "tde.h" + +/// Default constructor. +CTodoEntry::CTodoEntry (void) +: m_Text (), + m_Comment (), + m_Created (0), + m_Done (0), + m_Id (0), + m_Parent (0), + m_Priority (priority_Medium), + m_State (0) +{ +} + +/// Reads the object from stream \p is. +void CTodoEntry::read (istream& is) +{ + is >> m_Created >> m_Done + >> m_Id >> m_Parent >> m_Priority >> m_State + >> m_Text >> m_Comment; +} + +/// Writes the object to stream \p os. +void CTodoEntry::write (ostream& os) const +{ + os << m_Created << m_Done + << m_Id << m_Parent << m_Priority << m_State + << m_Text << m_Comment; +} + +/// Returns the size of the written object. +size_t CTodoEntry::stream_size (void) const +{ + return (Align (stream_size_of (m_Created) + + stream_size_of (m_Done) + + stream_size_of (m_Id) + + stream_size_of (m_Parent) + + stream_size_of (m_Priority) + + stream_size_of (m_State) + + stream_size_of (m_Text) + + stream_size_of (m_Comment))); +} + diff --git a/tde.h b/tde.h new file mode 100644 index 0000000..bfbf8c4 --- /dev/null +++ b/tde.h @@ -0,0 +1,42 @@ +// tde.h +// + +#ifndef TDE_H_27699F347D16DF25781577481B852F4D +#define TDE_H_27699F347D16DF25781577481B852F4D + +#include +using namespace ustl; + +/// ToDo list entry. +class CTodoEntry { +public: + enum EState { + state_Completed, + state_Last + }; + enum EPriority { + priority_Highest, + priority_High, + priority_Medium, + priority_Low, + priority_Lowest, + priority_Last + }; +public: + CTodoEntry (void); + void read (istream& is); + void write (ostream& os) const; + size_t stream_size (void) const; +public: + string m_Text; ///< Description of what to do. + string m_Comment; ///< Completion comment. + time_t m_Created; ///< When it was created. + time_t m_Done; ///< When it was completed. + uint32_t m_Id; ///< Unique id of the entry. + uint32_t m_Parent; ///< m_Id of the parent entry. + uint16_t m_Priority; ///< Priority value. See #EPriority. + uint16_t m_State; ///< State flags, see #EState. +}; + +#endif + diff --git a/todo.cc b/todo.cc new file mode 100644 index 0000000..4b30d3c --- /dev/null +++ b/todo.cc @@ -0,0 +1,116 @@ +#include "tde.h" +#include "tidrv.h" + +//---------------------------------------------------------------------- + +class CTodoApp { +public: + typedef int argc_t; + typedef const char* const* argv_t; +public: + static CTodoApp& Instance (void); + void Initialize (argc_t argc, argv_t argv); + int Run (void); +private: + typedef vector todolist_t; +private: + CTodoApp (void); + void AddTestEntries (todolist_t& tdl); + void Draw (void); +private: + CTerminfoBackend m_Device; + todolist_t m_Todos; +}; + +//---------------------------------------------------------------------- + +/// Default constructor. +CTodoApp::CTodoApp (void) +: m_Device (), + m_Todos () +{ +} + +/// Singleton interface. +/*static*/ CTodoApp& CTodoApp::Instance (void) +{ + static CTodoApp s_App; + return (s_App); +} + +/// Initializes the output device. +void CTodoApp::Initialize (argc_t, argv_t) +{ + m_Device.Initialize(); +} + +void CTodoApp::AddTestEntries (todolist_t& tdl) +{ + tdl.push_back(); + tdl.back().m_Text = "Entry 1"; + + tdl.push_back(); + tdl.back().m_Text = "Entry 2"; + + tdl.push_back(); + tdl.back().m_Text = "Entry 3"; + + tdl.push_back(); + tdl.back().m_Text = "Entry 4"; + + tdl.push_back(); + tdl.back().m_Text = "Entry 5"; + + tdl.push_back(); + tdl.back().m_Text = "Entry 6"; + + tdl.push_back(); + tdl.back().m_Text = "Entry 7"; + + tdl.push_back(); + tdl.back().m_Text = "Entry 8"; +} + +void CTodoApp::Draw (void) +{ + foreach (todolist_t::const_iterator, i, m_Todos) { + cout << m_Device.TI().Color (yellow) << i->m_Text << endl; + } +} + +int CTodoApp::Run (void) +{ + AddTestEntries (m_Todos); + wchar_t key = 0; + for (;;) { + Draw(); + m_Device.Flush(); + key = m_Device.GetKey(); + if (key == 'q') + break; + } + return (EXIT_SUCCESS); +} + +//---------------------------------------------------------------------- + +extern "C" void InstallCleanupHandlers (void); // in cleanup.cc + +int main (int argc, const char* const* argv) +{ + int rv = EXIT_FAILURE; + try { + InstallCleanupHandlers(); + CTodoApp& rApp (CTodoApp::Instance()); + rApp.Initialize (argc, argv); + rv = rApp.Run(); + } catch (exception& e) { + cout.flush(); + cerr << "Error: " << e << endl; + } catch (...) { + cout.flush(); + cerr << "Unexpected error occurred.\n"; + } + return (rv); +} + -- 2.11.4.GIT