diff --git a/src/API.cpp b/src/API.cpp index 0320b496d..10f9b0219 100644 --- a/src/API.cpp +++ b/src/API.cpp @@ -122,15 +122,6 @@ static int api_task_feature (lua_State* L) return 1; } -//////////////////////////////////////////////////////////////////////////////// -// Returns values from .taskrc, by name. -static int api_task_get_config (lua_State* L) -{ - std::string name = luaL_checkstring (L, 1); - lua_pushstring (L, context.config.get (name).c_str ()); - return 1; -} - //////////////////////////////////////////////////////////////////////////////// static int api_task_header_message (lua_State* L) { @@ -166,166 +157,6 @@ static int api_task_exit (lua_State* L) return 0; } -//////////////////////////////////////////////////////////////////////////////// -// -- 'id' is the task id passed to the hook function. Date attributes are -// -- returned as a numeric epoch offset. Tags and annotations are returned -// -- as tables. A nil value indicates a missing value. -static int api_task_get_uuid (lua_State* L) -{ - if (the_task != NULL) - lua_pushstring (L, the_task->get ("uuid").c_str ()); - else - lua_pushnil (L); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_description (lua_State* L) -{ - if (the_task != NULL) - lua_pushstring (L, the_task->get ("description").c_str ()); - else - lua_pushnil (L); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_project (lua_State* L) -{ - if (the_task != NULL) - lua_pushstring (L, the_task->get ("project").c_str ()); - else - lua_pushnil (L); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_priority (lua_State* L) -{ - if (the_task != NULL) - lua_pushstring (L, the_task->get ("priority").c_str ()); - else - lua_pushnil (L); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_status (lua_State* L) -{ - if (the_task != NULL) - lua_pushstring (L, Task::statusToText (the_task->getStatus ()).c_str ()); - else - lua_pushnil (L); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_due (lua_State* L) -{ - if (the_task != NULL) - { - unsigned int value = (unsigned int) the_task->get_ulong ("due"); - if (value) - { - lua_pushinteger (L, value); - return 1; - } - } - - lua_pushnil (L); - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_entry (lua_State* L) -{ - if (the_task != NULL) - { - unsigned int value = (unsigned int) the_task->get_ulong ("entry"); - if (value) - { - lua_pushinteger (L, value); - return 1; - } - } - - lua_pushnil (L); - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_start (lua_State* L) -{ - if (the_task != NULL) - { - unsigned int value = (unsigned int) the_task->get_ulong ("start"); - if (value) - { - lua_pushinteger (L, value); - return 1; - } - } - - lua_pushnil (L); - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_end (lua_State* L) -{ - if (the_task != NULL) - { - unsigned int value = (unsigned int) the_task->get_ulong ("end"); - if (value) - { - lua_pushinteger (L, value); - return 1; - } - } - - lua_pushnil (L); - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_until (lua_State* L) -{ - if (the_task != NULL) - { - unsigned int value = (unsigned int) the_task->get_ulong ("until"); - if (value) - { - lua_pushinteger (L, value); - return 1; - } - } - - lua_pushnil (L); - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -static int api_task_get_wait (lua_State* L) -{ - if (the_task != NULL) - { - unsigned int value = (unsigned int) the_task->get_ulong ("wait"); - if (value) - { - lua_pushinteger (L, value); - return 1; - } - } - - lua_pushnil (L); - return 1; -} - //////////////////////////////////////////////////////////////////////////////// API::API () : L (NULL) @@ -354,22 +185,10 @@ void API::initialize () lua_pushcfunction (L, api_task_lua_version); lua_setglobal (L, "task_lua_version"); lua_pushcfunction (L, api_task_os); lua_setglobal (L, "task_os"); lua_pushcfunction (L, api_task_feature); lua_setglobal (L, "task_feature"); - lua_pushcfunction (L, api_task_get_config); lua_setglobal (L, "task_get_config"); lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message"); lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message"); lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message"); lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit"); - lua_pushcfunction (L, api_task_get_uuid); lua_setglobal (L, "task_get_uuid"); - lua_pushcfunction (L, api_task_get_description); lua_setglobal (L, "task_get_description"); - lua_pushcfunction (L, api_task_get_project); lua_setglobal (L, "task_get_project"); - lua_pushcfunction (L, api_task_get_priority); lua_setglobal (L, "task_get_priority"); - lua_pushcfunction (L, api_task_get_status); lua_setglobal (L, "task_get_status"); - lua_pushcfunction (L, api_task_get_due); lua_setglobal (L, "task_get_due"); - lua_pushcfunction (L, api_task_get_entry); lua_setglobal (L, "task_get_entry"); - lua_pushcfunction (L, api_task_get_start); lua_setglobal (L, "task_get_start"); - lua_pushcfunction (L, api_task_get_end); lua_setglobal (L, "task_get_end"); - lua_pushcfunction (L, api_task_get_until); lua_setglobal (L, "task_get_until"); - lua_pushcfunction (L, api_task_get_wait); lua_setglobal (L, "task_get_wait"); } //////////////////////////////////////////////////////////////////////////////// @@ -416,24 +235,6 @@ bool API::callProgramHook ( return rc == 0 ? true : false; } -//////////////////////////////////////////////////////////////////////////////// -// TODO No intention of implementing this before task 2.0. Why? Because we -// need to implement a Lua iterator, in C++, to iterate over a std::vector. -bool API::callListHook ( - const std::string& file, - const std::string& function, - std::vector & all) -{ - loadFile (file); - - // TODO Get function. - // TODO Prepare args. - // TODO Make call. - // TODO Get exit status. - - return true; -} - //////////////////////////////////////////////////////////////////////////////// bool API::callTaskHook ( const std::string& file, diff --git a/src/API.h b/src/API.h index 01405dace..547ec1fe6 100644 --- a/src/API.h +++ b/src/API.h @@ -51,7 +51,6 @@ public: void initialize (); bool callProgramHook (const std::string&, const std::string&); - bool callListHook (const std::string&, const std::string&, std::vector &); bool callTaskHook (const std::string&, const std::string&, Task&); bool callFieldHook (const std::string&, const std::string&, const std::string&, std::string&); diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 6c089668f..5a0e8f21b 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -90,9 +90,21 @@ Hooks::Hooks () // Obsolete 1.x hooks. validProgramEvents.push_back ("post-start"); + validProgramEvents.push_back ("pre-exit"); + validProgramEvents.push_back ("pre-file-read"); + validProgramEvents.push_back ("post-file-read"); + validProgramEvents.push_back ("pre-file-write"); + validProgramEvents.push_back ("post-file-write"); + validProgramEvents.push_back ("pre-gc"); + validProgramEvents.push_back ("post-gc"); + + + + + + validProgramEvents.push_back ("post-commit"); validProgramEvents.push_back ("pre-fatal-error"); - validProgramEvents.push_back ("pre-exit"); validProgramEvents.push_back ("pre-command-line"); validProgramEvents.push_back ("post-command-line"); validProgramEvents.push_back ("pre-command-line-override"); @@ -109,10 +121,6 @@ Hooks::Hooks () validProgramEvents.push_back ("post-file-lock"); validProgramEvents.push_back ("pre-file-unlock"); validProgramEvents.push_back ("post-file-unlock"); - validProgramEvents.push_back ("pre-file-read"); - validProgramEvents.push_back ("post-file-read"); - validProgramEvents.push_back ("pre-file-write"); - validProgramEvents.push_back ("post-file-write"); validProgramEvents.push_back ("pre-output"); validProgramEvents.push_back ("post-output"); validProgramEvents.push_back ("pre-debug"); @@ -123,8 +131,6 @@ Hooks::Hooks () validProgramEvents.push_back ("post-footnote"); validProgramEvents.push_back ("pre-dispatch"); validProgramEvents.push_back ("post-dispatch"); - validProgramEvents.push_back ("pre-gc"); - validProgramEvents.push_back ("post-gc"); validProgramEvents.push_back ("pre-archive"); validProgramEvents.push_back ("post-archive"); validProgramEvents.push_back ("pre-purge"); @@ -212,9 +218,6 @@ Hooks::Hooks () validProgramEvents.push_back ("pre-version-command"); validProgramEvents.push_back ("post-version-command"); - validListEvents.push_back ("pre-filter"); - validListEvents.push_back ("post-filter"); - validTaskEvents.push_back ("pre-display"); validTaskEvents.push_back ("pre-modification"); validTaskEvents.push_back ("post-modification"); @@ -365,33 +368,6 @@ bool Hooks::trigger (const std::string& event) return true; } -//////////////////////////////////////////////////////////////////////////////// -// List hooks. -bool Hooks::trigger (const std::string& event, std::vector & tasks) -{ -#ifdef HAVE_LIBLUA - std::vector ::iterator it; - for (it = all.begin (); it != all.end (); ++it) - { - if (it->event == event) - { - Timer timer (std::string ("Hooks::trigger ") + event); - - if (validListEvent (event)) - { - context.debug (std::string ("Event ") + event + " triggered"); - if (! api.callListHook (it->file, it->function, tasks)) - return false; - } - else - throw std::string ("Unrecognized hook event '") + event + "'."; - } - } -#endif - - return true; -} - //////////////////////////////////////////////////////////////////////////////// // Task hooks. bool Hooks::trigger (const std::string& event, Task& task) @@ -458,14 +434,6 @@ bool Hooks::validProgramEvent (const std::string& event) return false; } -bool Hooks::validListEvent (const std::string& event) -{ - if (std::find (validListEvents.begin (), validListEvents.end (), event) != validListEvents.end ()) - return true; - - return false; -} - bool Hooks::validTaskEvent (const std::string& event) { if (std::find (validTaskEvents.begin (), validTaskEvents.end (), event) != validTaskEvents.end ()) diff --git a/src/Hooks.h b/src/Hooks.h index 881982127..bb153ada1 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -59,13 +59,11 @@ public: void initialize (); bool trigger (const std::string&); // Program - bool trigger (const std::string&, std::vector &); // List bool trigger (const std::string&, Task&); // Task bool trigger (const std::string&, const std::string&, std::string&); // Field private: bool validProgramEvent (const std::string&); - bool validListEvent (const std::string&); bool validTaskEvent (const std::string&); bool validFieldEvent (const std::string&); @@ -76,7 +74,6 @@ private: std::vector all; // All current hooks. std::vector validProgramEvents; - std::vector validListEvents; std::vector validTaskEvents; std::vector validFieldEvents; };