From: Philip Withnall Date: Thu, 25 Aug 2011 18:17:27 +0000 (+0100) Subject: Bug 657332 — Add linking link-individuals X-Git-Tag: FOLKS_0.6.1~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=92c819b7f0fccc742f8de464969abf8316384172;p=platform%2Fupstream%2Ffolks.git Bug 657332 — Add linking link-individuals Add a `linking link-individuals` subcommand to folks-inspect. Note: this appears to break readline command completion for the `linking` command in certain situations (e.g. if you tab-complete the name of the command first). I can't fix this for love or money. Pigs will fly before I manage to work out why readline hates me so much. Closes: bgo#657332 --- diff --git a/NEWS b/NEWS index 520076b..2a8e56f 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Bugs fixed: * Bug 656659 — Use vcards for postal addresses * Bug 655374 — Un-break avatar tests * Bug 657067 — Can't build EDS backend using Vala master +* Bug 657332 — Add linking link-individuals Overview of changes from libfolks 0.5.2 to libfolks 0.5.3 ========================================================= diff --git a/tools/inspect/command-linking.vala b/tools/inspect/command-linking.vala index e1cc34b..8b1585c 100644 --- a/tools/inspect/command-linking.vala +++ b/tools/inspect/command-linking.vala @@ -41,9 +41,14 @@ private class Folks.Inspect.Commands.Linking : Folks.Inspect.Command { get { - return "linking link-personas [persona 1 UID] [persona 2 UID] … " + + return "linking link-personas [persona 1 UID] " + + "[persona 2 UID] … " + "Link the given personas.\n" + - "linking unlink-individual [individual ID] " + + "linking link-individuals [individual 1 ID] " + + "[individual 2 ID] … " + + "Link the personas in the given individuals.\n" + + "linking unlink-individual " + + "[individual ID] " + "Unlink the given individual."; } } @@ -64,59 +69,111 @@ private class Folks.Inspect.Commands.Linking : Folks.Inspect.Command } if (parts.length < 1 || - (parts[0] != "link-personas" && parts[0] != "unlink-individual")) + (parts[0] != "link-personas" && parts[0] != "link-individuals" && + parts[0] != "unlink-individual")) { Utils.print_line ("Unrecognised 'linking' command '%s'.", command_string); return; } - if (parts[0] == "link-personas") + if (parts[0] == "link-personas" || parts[0] == "link-individuals") { var personas = new HashSet (); /* set of personas to link */ if (parts.length < 2) { - Utils.print_line ("Must pass at least one persona to a " + - "'link-personas' subcommand."); + if (parts[0] == "link-personas") + { + Utils.print_line ("Must pass at least one persona to a " + + "'link-personas' subcommand."); + } + else + { + Utils.print_line ("Must pass at least one individual to a " + + "'link-individuals' subcommand."); + } + return; } - /* Link the given personas. We must have at least one. */ + /* Link the personas in the given individuals. We must have at least + * one. */ for (uint i = 1; i < parts.length; i++) { if (parts[i] == null || parts[i].strip () == "") { - Utils.print_line ("Unrecognised persona UID '%s'.", parts[i]); + if (parts[0] == "link-personas") + { + Utils.print_line ("Unrecognised persona UID '%s'.", + parts[i]); + } + else + { + Utils.print_line ("Unrecognised individual ID '%s'.", + parts[i]); + } + return; } var found = false; - var uid = parts[i].strip (); - foreach (var individual in - this.client.aggregator.individuals.values) + if (parts[0] == "link-personas") { - foreach (Persona persona in individual.personas) + var uid = parts[i].strip (); + + foreach (var individual in + this.client.aggregator.individuals.values) { - if (persona.uid == uid) + foreach (Persona persona in individual.personas) + { + if (persona.uid == uid) + { + personas.add (persona); + found = true; + break; + } + } + + if (found == true) { - personas.add (persona); - found = true; break; } } - if (found == true) + if (found == false) { - break; + Utils.print_line ("Unrecognised persona UID '%s'.", + parts[i]); + return; } } - - if (found == false) + else { - Utils.print_line ("Unrecognised persona UID '%s'.", parts[i]); - return; + var id = parts[i].strip (); + + foreach (var individual in + this.client.aggregator.individuals.values) + { + if (individual.id == id) + { + foreach (Persona persona in individual.personas) + { + personas.add (persona); + } + + found = true; + break; + } + } + + if (found == false) + { + Utils.print_line ("Unrecognised individual ID '%s'.", + parts[i]); + return; + } } } @@ -192,8 +249,8 @@ private class Folks.Inspect.Commands.Linking : Folks.Inspect.Command private static uint completion_count; private static string prefix; - /* Complete a subcommand name (either “link-personas” or “unlink-individual”), - * starting with @word. */ + /* Complete a subcommand name (either “link-personas”, “link-individuals” + * or “unlink-individual”), starting with @word. */ public static string? subcommand_name_completion_cb (string word, int state) { @@ -203,13 +260,23 @@ private class Folks.Inspect.Commands.Linking : Folks.Inspect.Command { string[] parts = word.split (" "); - if (parts.length > 0 && parts[0] == "link-personas") + if (parts.length > 0 && + (parts[0] == "link-personas" || parts[0] == "link-individuals")) { var last_part = parts[parts.length - 1]; - subcommand_completions = - Readline.completion_matches (last_part, - Utils.persona_uid_completion_cb); + if (parts[0] == "link-personas") + { + subcommand_completions = + Readline.completion_matches (last_part, + Utils.persona_uid_completion_cb); + } + else + { + subcommand_completions = + Readline.completion_matches (last_part, + Utils.individual_id_completion_cb); + } if (last_part == "") { @@ -241,7 +308,8 @@ private class Folks.Inspect.Commands.Linking : Folks.Inspect.Command else { subcommand_completions = - { "link-personas", "unlink-individual", null }; + { "link-personas", "link-individuals", + "unlink-individual", null }; prefix = ""; } @@ -271,7 +339,8 @@ private class Folks.Inspect.Commands.Linking : Folks.Inspect.Command public override string[]? complete_subcommand (string subcommand) { - /* @subcommand should be either “link-personas” or “unlink-individual” */ + /* @subcommand should be either “link-personas”, “link-individuals” + * or “unlink-individual” */ return Readline.completion_matches (subcommand, this.subcommand_name_completion_cb); }