From 7233fcd05b9c453592fc8e84e0f79cd599361c10 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 12 Jul 2010 20:25:33 -0400 Subject: [PATCH] Dependencies - add - Allowed dependencies to be specified when adding a new task. --- src/command.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index e12c3b727..d4d82ca90 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -99,19 +99,40 @@ int handleAdd (std::string &outs) !context.task.has ("recur")) throw std::string ("You cannot specify an until date for a non-recurring task."); - // TODO Resolve dependencies. + // Must load pending to resolve dependencies, and to provide a new ID. + context.tdb.lock (context.config.getBoolean ("locking")); + + std::vector all; + Filter none; + context.tdb.loadPending (all, none); + + // Resolve dependencies. + if (context.task.has ("depends")) + { + // Convert ID to UUID. + std::vector deps; + split (deps, context.task.get ("depends"), ','); + + // Eliminate the ID-based set. + context.task.set ("depends", ""); + + std::vector ::iterator i; + for (i = deps.begin (); i != deps.end (); i++) + { + int id = atoi (i->c_str ()); + if (id < 0) + context.task.removeDependency (-id); + else + context.task.addDependency (id); + } + } // Only valid tasks can be added. context.task.validate (); - context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.add (context.task); #ifdef FEATURE_NEW_ID - // All this, just for an id number. - std::vector all; - Filter none; - context.tdb.loadPending (all, none); out << "Created task " << context.tdb.nextId () << std::endl; #endif