[folks] Bug 657332 — Add linking link-individuals



commit 92c819b7f0fccc742f8de464969abf8316384172
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Aug 25 19:17:27 2011 +0100

    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

 NEWS                               |    1 +
 tools/inspect/command-linking.vala |  127 +++++++++++++++++++++++++++--------
 2 files changed, 99 insertions(+), 29 deletions(-)
---
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<Persona> (); /* 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);
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]