/soc/2015/igor.gajowiak/chatlog: 4f8245b0afb9: Fixed protocol na...
Igor Gajowiak <[email protected]>
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 4f8245b0afb96e50ac7352f18df5e5574ee5df17 Author: Igor Gajowiak <[email protected]> Date: 2015-08-15 15:45 +0200 Branch: default URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/4f8245b0afb9 Description: Fixed protocol name normalization in the legacy log. diffstat: libpurple/plugins/log/legacylog.c | 39 ++++++++++++++++++++++++++++++--------- 1 files changed, 30 insertions(+), 9 deletions(-) diffs (80 lines): diff --git a/libpurple/plugins/log/legacylog.c b/libpurple/plugins/log/legacylog.c --- a/libpurple/plugins/log/legacylog.c +++ b/libpurple/plugins/log/legacylog.c @@ -42,6 +42,8 @@ static GRegex *date_regex = NULL; static GRegex *time_regex = NULL; static GRegex *contact_regex = NULL; +static GHashTable *protocol_icon_to_id_hash = NULL; + typedef enum { DIR_DEPTH_PROTOCOL = 1, @@ -293,18 +295,12 @@ uninit_iter(Iter *iter) uninit_iter_at_depth(iter, i); } -/* - * TODO: check all protocols - */ static const gchar * normalize_protocol_name(const gchar *protocol) { - if (strcmp(protocol, "jabber") == 0) - return "prpl-jabber"; - else if (strcmp(protocol, "gadu-gadu") == 0) - return "prpl-gg"; - else - return protocol; + gpointer protocol_id = g_hash_table_lookup( + protocol_icon_to_id_hash, protocol); + return protocol_id ? (const gchar *) protocol_id : ""; } static gboolean @@ -672,6 +668,27 @@ plugin_query(GError **error) ); } +static GHashTable * +init_protocol_icon_to_id_hash() +{ + GHashTable *res = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + g_free); + + GList *protocols = purple_protocols_get_all(); + + for (GList *it = protocols; it != NULL; it = it->next) { + PurpleProtocol *protocol = PURPLE_PROTOCOL(it->data); + + g_hash_table_insert(res, + g_strdup(purple_protocol_class_list_icon(protocol, NULL, NULL)), + g_strdup(purple_protocol_get_id(protocol))); + } + + g_list_free(protocols); + + return res; +} + static gboolean plugin_load(PurplePlugin *plugin, GError **error) { @@ -697,6 +714,8 @@ plugin_load(PurplePlugin *plugin, GError contact_regex = g_regex_new("^(.*)\\.chat$", 0, 0, NULL); g_assert(contact_regex); + protocol_icon_to_id_hash = init_protocol_icon_to_id_hash(); + return TRUE; } @@ -712,6 +731,8 @@ plugin_unload(PurplePlugin *plugin, GErr g_object_unref(legacylog_instance); legacylog_instance = NULL; + g_hash_table_destroy(protocol_icon_to_id_hash); + return TRUE; } _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits