Advertisement
tomkiewicz

pidgin-libpurple-accountopt-hinted-string-1

Aug 10th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.51 KB | None | 0 0
  1. diff --git a/libpurple/accountopt.c b/libpurple/accountopt.c
  2. --- a/libpurple/accountopt.c
  3. +++ b/libpurple/accountopt.c
  4. @@ -50,10 +50,17 @@
  5.  
  6.     } default_value;
  7.  
  8. -   gboolean masked;        /**< Whether the value entered should be
  9. -                            *   obscured from view (for passwords and
  10. -                            *   similar options)
  11. -                            */
  12. +   union
  13. +   {
  14. +       struct
  15. +       {
  16. +           gboolean masked; /**< Whether the value entered should
  17. +                             *   be obscured from view (for
  18. +                             *   passwords and similar options)
  19. +                             */
  20. +           GList *hints;    /**< List of hinted values */
  21. +       } string;
  22. +   } params;
  23.  };
  24.  
  25.  /**
  26. @@ -177,6 +184,7 @@
  27.     if (option->type == PURPLE_PREF_STRING)
  28.     {
  29.         g_free(option->default_value.string);
  30. +       g_list_free_full(option->params.string.hints, &g_free);
  31.     }
  32.     else if (option->type == PURPLE_PREF_STRING_LIST)
  33.     {
  34. @@ -221,14 +229,23 @@
  35.  }
  36.  
  37.  void
  38. -purple_account_option_set_masked(PurpleAccountOption *option, gboolean masked)
  39. +purple_account_option_string_set_masked(PurpleAccountOption *option, gboolean masked)
  40.  {
  41.     g_return_if_fail(option != NULL);
  42.     g_return_if_fail(option->type == PURPLE_PREF_STRING);
  43.  
  44. -   option->masked = masked;
  45. +   option->params.string.masked = masked;
  46.  }
  47.  
  48. +void
  49. +purple_account_option_string_set_hints(PurpleAccountOption *option, GList *hints)
  50. +{
  51. +   g_return_if_fail(option != NULL);
  52. +   g_return_if_fail(option->type == PURPLE_PREF_STRING);
  53. +
  54. +   g_list_free_full(option->params.string.hints, &g_free);
  55. +   option->params.string.hints = hints;
  56. +}
  57.  
  58.  void
  59.  purple_account_option_set_list(PurpleAccountOption *option, GList *values)
  60. @@ -332,12 +349,21 @@
  61.  }
  62.  
  63.  gboolean
  64. -purple_account_option_get_masked(const PurpleAccountOption *option)
  65. +purple_account_option_string_get_masked(const PurpleAccountOption *option)
  66.  {
  67.     g_return_val_if_fail(option != NULL, FALSE);
  68.     g_return_val_if_fail(option->type == PURPLE_PREF_STRING, FALSE);
  69.  
  70. -   return option->masked;
  71. +   return option->params.string.masked;
  72. +}
  73. +
  74. +const GList *
  75. +purple_account_option_string_get_hints(const PurpleAccountOption *option)
  76. +{
  77. +   g_return_val_if_fail(option != NULL, FALSE);
  78. +   g_return_val_if_fail(option->type == PURPLE_PREF_STRING, FALSE);
  79. +
  80. +   return option->params.string.hints;
  81.  }
  82.  
  83.  GList *
  84. diff --git a/libpurple/accountopt.h b/libpurple/accountopt.h
  85. --- a/libpurple/accountopt.h
  86. +++ b/libpurple/accountopt.h
  87. @@ -158,7 +158,19 @@
  88.   * @param masked The masking.
  89.   */
  90.  void
  91. -purple_account_option_set_masked(PurpleAccountOption *option, gboolean masked);
  92. +purple_account_option_string_set_masked(PurpleAccountOption *option, gboolean masked);
  93. +
  94. +/**
  95. + * Sets the hint list for an account option.
  96. + *
  97. + * The list passed will be owned by the account option, and the
  98. + * strings inside will be freed automatically.
  99. + *
  100. + * @param option The account option.
  101. + * @param hints The list of hints, stored as strings.
  102. + */
  103. +void purple_account_option_string_set_hints(PurpleAccountOption *option,
  104. +   GList *hints);
  105.  
  106.  /**
  107.   * Sets the list values for an account option.
  108. @@ -261,7 +273,16 @@
  109.   * @return %TRUE if the option's value should be obscured.
  110.   */
  111.  gboolean
  112. -purple_account_option_get_masked(const PurpleAccountOption *option);
  113. +purple_account_option_string_get_masked(const PurpleAccountOption *option);
  114. +
  115. +/**
  116. + * Returns the list of hints for an account option.
  117. + *
  118. + * @param option The account option.
  119. + *
  120. + * @constreturn A list of hints, stored as strings.
  121. + */
  122. +const GList * purple_account_option_string_get_hints(const PurpleAccountOption *option);
  123.  
  124.  /**
  125.   * Returns the list values for an account option.
  126. diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
  127. --- a/libpurple/protocols/gg/gg.c
  128. +++ b/libpurple/protocols/gg/gg.c
  129. @@ -2136,12 +2136,19 @@
  130.  {
  131.     PurpleAccountOption *option;
  132.     GList *encryption_options = NULL;
  133. +   GList *server_hints = NULL;
  134.  
  135.     purple_debug_info("gg", "Loading Gadu-Gadu protocol plugin with "
  136.         "libgadu %s...\n", gg_libgadu_version());
  137.  
  138. +   server_hints = g_list_append(server_hints, g_strdup("hint1"));
  139. +   server_hints = g_list_append(server_hints, g_strdup("hint2"));
  140. +   server_hints = g_list_append(server_hints, g_strdup("hint3"));
  141. +   server_hints = g_list_append(server_hints, g_strdup("hint4"));
  142. +
  143.     option = purple_account_option_string_new(_("GG server"),
  144.             "gg_server", "");
  145. +   purple_account_option_string_set_hints(option, server_hints);
  146.     prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
  147.             option);
  148.  
  149. diff --git a/pidgin/gtkaccount.c b/pidgin/gtkaccount.c
  150. --- a/pidgin/gtkaccount.c
  151. +++ b/pidgin/gtkaccount.c
  152. @@ -812,6 +812,7 @@
  153.     const char *str_value;
  154.     gboolean bool_value;
  155.     ProtocolOptEntry *opt_entry;
  156. +   const GList *str_hints;
  157.  
  158.     if (dialog->protocol_frame != NULL) {
  159.         gtk_notebook_remove_page (GTK_NOTEBOOK(dialog->notebook), 1);
  160. @@ -912,8 +913,25 @@
  161.                         purple_account_option_get_default_string(option));
  162.                 }
  163.  
  164. -               opt_entry->widget = entry = gtk_entry_new();
  165. -               if (purple_account_option_get_masked(option))
  166. +               str_hints = purple_account_option_string_get_hints(option);
  167. +               if (str_hints)
  168. +               {
  169. +                   const GList *hint_it = str_hints;
  170. +                   entry = gtk_combo_box_entry_new_text();
  171. +                   while (hint_it)
  172. +                   {
  173. +                       const gchar *hint = hint_it->data;
  174. +                       hint_it = g_list_next(hint_it);
  175. +                       gtk_combo_box_append_text(GTK_COMBO_BOX(entry), hint);
  176. +                   }
  177. +               }
  178. +               else
  179. +                   entry = gtk_entry_new();
  180. +              
  181. +               opt_entry->widget = entry;
  182. +               if (purple_account_option_string_get_masked(option) && str_hints)
  183. +                   g_warn_if_reached();
  184. +               else if (purple_account_option_string_get_masked(option))
  185.                 {
  186.                     gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
  187.  #if !GTK_CHECK_VERSION(2,16,0)
  188. @@ -922,7 +940,9 @@
  189.  #endif /* Less than GTK+ 2.16 */
  190.                 }
  191.  
  192. -               if (str_value != NULL)
  193. +               if (str_value != NULL && str_hints)
  194. +                   gtk_entry_set_text(GTK_ENTRY(GTK_BIN(entry)->child), str_value);
  195. +               else
  196.                     gtk_entry_set_text(GTK_ENTRY(entry), str_value);
  197.  
  198.                 title = g_strdup_printf("_%s:",
  199. @@ -1453,7 +1473,10 @@
  200.  
  201.             switch (opt_entry->type) {
  202.                 case PURPLE_PREF_STRING:
  203. -                   value = gtk_entry_get_text(GTK_ENTRY(opt_entry->widget));
  204. +                   if (GTK_IS_COMBO_BOX(opt_entry->widget))
  205. +                       value = gtk_combo_box_get_active_text(GTK_COMBO_BOX(opt_entry->widget));
  206. +                   else
  207. +                       value = gtk_entry_get_text(GTK_ENTRY(opt_entry->widget));
  208.                     purple_account_set_string(account, opt_entry->setting, value);
  209.                     break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement