| |
1 /* pidgin |
| |
2 * |
| |
3 * Pidgin is the legal property of its developers, whose names are too numerous |
| |
4 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
5 * source distribution. |
| |
6 * |
| |
7 * This program is free software; you can redistribute it and/or modify |
| |
8 * it under the terms of the GNU General Public License as published by |
| |
9 * the Free Software Foundation; either version 2 of the License, or |
| |
10 * (at your option) any later version. |
| |
11 * |
| |
12 * This program is distributed in the hope that it will be useful, |
| |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
15 * GNU General Public License for more details. |
| |
16 * |
| |
17 * You should have received a copy of the GNU General Public License |
| |
18 * along with this program; if not, write to the Free Software |
| |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| |
20 */ |
| |
21 |
| |
22 #include <talkatu.h> |
| |
23 |
| |
24 #include "internal.h" |
| |
25 #include "plugins.h" |
| |
26 |
| |
27 #include "pidgindebugplugininfo.h" |
| |
28 |
| |
29 /** |
| |
30 * SECTION:pidgindebugplugininfo |
| |
31 * @Title: Debug Plugin Info |
| |
32 * @Short_description: A widget that lists verbose plugin info |
| |
33 * |
| |
34 * When helping users troubleshoot issues with Pidgin we often need to know |
| |
35 * what plugins that have installed/running. This widget gives them an easy |
| |
36 * way to get that info to us. |
| |
37 */ |
| |
38 |
| |
39 typedef struct { |
| |
40 GtkTextBuffer *buffer; |
| |
41 GtkWidget *view; |
| |
42 } PidginDebugPluginInfoPrivate; |
| |
43 |
| |
44 G_DEFINE_TYPE_WITH_PRIVATE(PidginDebugPluginInfo, pidgin_debug_plugin_info, GTK_TYPE_DIALOG) |
| |
45 |
| |
46 /****************************************************************************** |
| |
47 * Helpers |
| |
48 *****************************************************************************/ |
| |
49 static gchar * |
| |
50 pidgin_debug_plugin_info_build_html(void) { |
| |
51 GString *str = g_string_new(NULL); |
| |
52 GList *plugins = NULL, *l = NULL; |
| |
53 GError *error = NULL; |
| |
54 gchar *ret = NULL; |
| |
55 |
| |
56 g_string_append_printf(str, "<h2>%s</h2><dl>", _("Plugin Information")); |
| |
57 |
| |
58 plugins = purple_plugins_find_all(); |
| |
59 for(l = plugins; l != NULL; l = l->next) { |
| |
60 PurplePlugin *plugin = PURPLE_PLUGIN(l->data); |
| |
61 PurplePluginInfo *info = purple_plugin_get_info(plugin); |
| |
62 PurplePluginExtraCb extra_cb; |
| |
63 gchar *name = g_markup_escape_text(purple_plugin_info_get_name(info), -1); |
| |
64 gchar *version, *license, *website, *id; |
| |
65 gchar *authors = NULL, *extra = NULL; |
| |
66 const gchar *error_message = NULL; |
| |
67 const gchar * const *authorsv; |
| |
68 gboolean loaded; |
| |
69 |
| |
70 g_object_get( |
| |
71 G_OBJECT(info), |
| |
72 "authors", &authorsv, |
| |
73 "version", &version, |
| |
74 "license-id", &license, |
| |
75 "website", &website, |
| |
76 "id", &id, |
| |
77 "extra-cb", &extra_cb, |
| |
78 NULL |
| |
79 ); |
| |
80 |
| |
81 if(authorsv != NULL) { |
| |
82 gchar *authorstmp = g_strjoinv(", ", (gchar **)authorsv); |
| |
83 g_strfreev(authorsv); |
| |
84 |
| |
85 authors = g_markup_escape_text(authorstmp, -1); |
| |
86 g_free(authorstmp); |
| |
87 } |
| |
88 |
| |
89 if(extra_cb != NULL) { |
| |
90 extra = extra_cb(plugin); |
| |
91 } |
| |
92 |
| |
93 error_message = purple_plugin_info_get_error(info); |
| |
94 |
| |
95 loaded = purple_plugin_is_loaded(plugin); |
| |
96 |
| |
97 g_string_append_printf(str, "<dt>%s</dt><dd>", name); |
| |
98 g_free(name); |
| |
99 |
| |
100 /* this is not translated as it's meant for debugging */ |
| |
101 g_string_append_printf( |
| |
102 str, |
| |
103 "<b>Authors:</b> %s<br/>" |
| |
104 "<b>Version:</b> %s<br/>" |
| |
105 "<b>License:</b> %s<br/>" |
| |
106 "<b>Website:</b> %s<br/>" |
| |
107 "<b>ID:</b> %s<br/>" |
| |
108 "<b>Extra:</b> %s<br/>" |
| |
109 "<b>Errors:</b> %s</br>" |
| |
110 "<b>Loaded:</b> %s", |
| |
111 authors ? authors : "", |
| |
112 version ? version : "", |
| |
113 license ? license : "", |
| |
114 website ? website : "", |
| |
115 id ? id : "", |
| |
116 extra ? extra : "", |
| |
117 error_message ? error_message : "", |
| |
118 loaded ? "Yes" : "No" |
| |
119 ); |
| |
120 |
| |
121 g_free(authors); |
| |
122 g_free(version); |
| |
123 g_free(license); |
| |
124 g_free(website); |
| |
125 g_free(id); |
| |
126 g_free(extra); |
| |
127 |
| |
128 g_string_append(str, "</dd>"); |
| |
129 } |
| |
130 |
| |
131 g_list_free(plugins); |
| |
132 |
| |
133 g_string_append(str, "</dl>"); |
| |
134 |
| |
135 return g_string_free(str, FALSE); |
| |
136 } |
| |
137 |
| |
138 /****************************************************************************** |
| |
139 * GObject Stuff |
| |
140 *****************************************************************************/ |
| |
141 static void |
| |
142 pidgin_debug_plugin_info_init(PidginDebugPluginInfo *debug_plugin_info) { |
| |
143 gtk_widget_init_template(GTK_WIDGET(debug_plugin_info)); |
| |
144 } |
| |
145 |
| |
146 static void |
| |
147 pidgin_debug_plugin_info_class_init(PidginDebugPluginInfoClass *klass) { |
| |
148 gtk_widget_class_set_template_from_resource( |
| |
149 GTK_WIDGET_CLASS(klass), |
| |
150 "/im/pidgin/Pidgin/Debug/plugininfo.ui" |
| |
151 ); |
| |
152 |
| |
153 gtk_widget_class_bind_template_child_private(klass, PidginDebugPluginInfo, buffer); |
| |
154 gtk_widget_class_bind_template_child_private(klass, PidginDebugPluginInfo, view); |
| |
155 } |
| |
156 |
| |
157 /****************************************************************************** |
| |
158 * Public API |
| |
159 *****************************************************************************/ |
| |
160 |
| |
161 /** |
| |
162 * pidgin_debug_plugin_info_new: |
| |
163 * |
| |
164 * Creates a new #PidginDebugPluginInfo that provides the user with an easy way |
| |
165 * to share information about their plugin state for debugging purposes. |
| |
166 * |
| |
167 * Returns: (transfer full): The new #PidginDebugPluginInfo instance. |
| |
168 */ |
| |
169 GtkWidget *pidgin_debug_plugin_info_new(void) { |
| |
170 return GTK_WIDGET(g_object_new( |
| |
171 PIDGIN_TYPE_DEBUG_PLUGIN_INFO, |
| |
172 NULL |
| |
173 )); |
| |
174 } |
| |
175 |
| |
176 void |
| |
177 pidgin_debug_plugin_info_show(void) { |
| |
178 PidginDebugPluginInfoPrivate *priv = NULL; |
| |
179 GtkWidget *win = NULL; |
| |
180 gchar *text = NULL; |
| |
181 |
| |
182 win = pidgin_debug_plugin_info_new(); |
| |
183 priv = pidgin_debug_plugin_info_get_instance_private(PIDGIN_DEBUG_PLUGIN_INFO(win)); |
| |
184 |
| |
185 text = pidgin_debug_plugin_info_build_html(); |
| |
186 g_warning("text: '%s'", text); |
| |
187 talkatu_markup_set_html(TALKATU_BUFFER(priv->buffer), text, -1); |
| |
188 g_free(text); |
| |
189 |
| |
190 gtk_widget_show_all(win); |
| |
191 gtk_window_present(GTK_WINDOW(win)); |
| |
192 } |