- Provided protocol version in sync message.
- Improved feedback messages.
This commit is contained in:
Paul Beckingham 2012-10-10 23:34:52 -04:00
parent d060bf166d
commit 8fa7d135db

View file

@ -25,6 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO Localize new messages, when they stabilize.
#define L10N // Localization complete. #define L10N // Localization complete.
#include <iostream> #include <iostream>
@ -76,10 +77,11 @@ int CmdSync::execute (std::string& output)
// Send 'sync' + payload. // Send 'sync' + payload.
Msg request, response; Msg request, response;
request.set ("type", "sync"); request.set ("protocol", "v1");
request.set ("org", credentials[0]); request.set ("type", "sync");
request.set ("user", credentials[1]); request.set ("org", credentials[0]);
request.set ("key", credentials[2]); request.set ("user", credentials[1]);
request.set ("key", credentials[2]);
// TODO Add the other header fields. // TODO Add the other header fields.
@ -101,6 +103,7 @@ int CmdSync::execute (std::string& output)
// Load all tasks. // Load all tasks.
// TODO This is not necessary if only a synch key was received. // TODO This is not necessary if only a synch key was received.
// TODO Furthermore, 'all' is not used.
std::vector <Task> all = context.tdb2.all_tasks (); std::vector <Task> all = context.tdb2.all_tasks ();
std::string synch_key = ""; std::string synch_key = "";
@ -155,28 +158,28 @@ int CmdSync::execute (std::string& output)
// Commit all changes. // Commit all changes.
context.tdb2.commit (); context.tdb2.commit ();
context.footnote ("Sync complete. Changes applied."); context.footnote ("Sync successful.");
/* // TODO Sync successful. 2 tasks uploaded.
TODO We can do better: // TODO Sync successful. 4 tasks downloaded.
// TODO Sync successful. 2 tasks uploaded, 4 tasks downloaded.
Sync complete. 2 changes sent, 1 addition, 3 modifications received.
Sync complete. 2 local changes, 4 remote changes.
*/
} }
} }
else if (code == "201") else if (code == "201")
{ {
context.footnote ("Sync complete. No Change."); context.footnote ("Sync successful. No updates required.");
} }
else if (code == "430") else if (code == "430")
{ {
context.error ("Not authorized. Could be incorrect credentials or " context.error ("Sync failed. Either your credentials are incorrect, or "
"server account not enabled."); "your Task Server account is not enabled.");
status = 2; status = 2;
} }
else else
{ {
context.error ("Task Server error: " + code + " " + response.get ("status")); context.error ("Sync failed. The Task Server returned error: " +
code +
" " +
response.get ("status"));
status = 2; status = 2;
} }
@ -199,7 +202,7 @@ int CmdSync::execute (std::string& output)
// - Network error // - Network error
else else
{ {
context.error ("Could not connect to Task Server."); context.error ("Sync failed. Could not connect to the Task Server.");
status = 1; status = 1;
} }