| 20 * along with this program; if not, see <https://www.gnu.org/licenses/>. |
20 * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 21 */ |
21 */ |
| 22 |
22 |
| 23 #include "pidgin/pidgininfopane.h" |
23 #include "pidgin/pidgininfopane.h" |
| 24 |
24 |
| 25 #include "pidgin/gtkblist.h" |
|
| 26 #include "pidgin/gtkutils.h" |
|
| 27 #include "pidgin/pidginavatar.h" |
|
| 28 #include "pidgin/pidgincore.h" |
|
| 29 #include "pidgin/pidginpresenceicon.h" |
|
| 30 |
|
| 31 struct _PidginInfoPane { |
25 struct _PidginInfoPane { |
| 32 GtkBox parent; |
26 GtkBox parent; |
| 33 |
27 |
| 34 PurpleConversation *conversation; |
28 PurpleConversation *conversation; |
| 35 |
29 |
| 36 GtkWidget *hbox; |
|
| 37 GtkWidget *avatar; |
|
| 38 |
|
| 39 GtkWidget *name; |
|
| 40 GBinding *name_binding; |
|
| 41 |
|
| 42 GtkWidget *topic; |
30 GtkWidget *topic; |
| 43 GBinding *topic_binding; |
|
| 44 }; |
31 }; |
| 45 |
32 |
| 46 enum { |
33 enum { |
| 47 PROP_0, |
34 PROP_0, |
| 48 PROP_CONVERSATION, |
35 PROP_CONVERSATION, |
| 51 static GParamSpec *properties[N_PROPERTIES] = {NULL, }; |
38 static GParamSpec *properties[N_PROPERTIES] = {NULL, }; |
| 52 |
39 |
| 53 G_DEFINE_TYPE(PidginInfoPane, pidgin_info_pane, GTK_TYPE_BOX) |
40 G_DEFINE_TYPE(PidginInfoPane, pidgin_info_pane, GTK_TYPE_BOX) |
| 54 |
41 |
| 55 /****************************************************************************** |
42 /****************************************************************************** |
| 56 * Helpers |
43 * Callbacks |
| 57 *****************************************************************************/ |
44 *****************************************************************************/ |
| 58 static gboolean |
45 static char * |
| 59 pidgin_info_pane_topic_to_label(G_GNUC_UNUSED GBinding *binding, |
46 pidgin_info_pane_linkify_text_cb(GObject *self, const char *topic, |
| 60 const GValue *from_value, |
47 G_GNUC_UNUSED gpointer data) |
| 61 GValue *to_value, |
|
| 62 gpointer data) |
|
| 63 { |
48 { |
| 64 PidginInfoPane *pane = data; |
49 PidginInfoPane *pane = PIDGIN_INFO_PANE(self); |
| 65 const char *topic = NULL; |
50 char *ret = NULL; |
| 66 gboolean visible = FALSE; |
|
| 67 |
51 |
| 68 topic = g_value_get_string(from_value); |
52 ret = purple_markup_linkify(topic); |
| 69 visible = !purple_strempty(topic); |
53 gtk_widget_set_visible(pane->topic, !purple_strempty(ret)); |
| 70 g_value_set_string(to_value, topic); |
|
| 71 |
54 |
| 72 gtk_widget_set_visible(pane->topic, visible); |
55 return ret; |
| 73 |
|
| 74 return TRUE; |
|
| 75 } |
56 } |
| 76 |
57 |
| 77 /****************************************************************************** |
58 /****************************************************************************** |
| 78 * GObject Implementation |
59 * GObject Implementation |
| 79 *****************************************************************************/ |
60 *****************************************************************************/ |
| 148 gtk_widget_class_set_template_from_resource( |
129 gtk_widget_class_set_template_from_resource( |
| 149 widget_class, |
130 widget_class, |
| 150 "/im/pidgin/Pidgin3/Conversations/infopane.ui" |
131 "/im/pidgin/Pidgin3/Conversations/infopane.ui" |
| 151 ); |
132 ); |
| 152 |
133 |
| 153 gtk_widget_class_bind_template_child(widget_class, PidginInfoPane, hbox); |
|
| 154 gtk_widget_class_bind_template_child(widget_class, PidginInfoPane, avatar); |
|
| 155 gtk_widget_class_bind_template_child(widget_class, PidginInfoPane, name); |
|
| 156 gtk_widget_class_bind_template_child(widget_class, PidginInfoPane, topic); |
134 gtk_widget_class_bind_template_child(widget_class, PidginInfoPane, topic); |
| |
135 |
| |
136 gtk_widget_class_bind_template_callback(widget_class, |
| |
137 pidgin_info_pane_linkify_text_cb); |
| 157 } |
138 } |
| 158 |
139 |
| 159 /****************************************************************************** |
140 /****************************************************************************** |
| 160 * API |
141 * API |
| 161 *****************************************************************************/ |
142 *****************************************************************************/ |
| 182 |
163 |
| 183 if(!g_set_object(&pane->conversation, conversation)) { |
164 if(!g_set_object(&pane->conversation, conversation)) { |
| 184 return; |
165 return; |
| 185 } |
166 } |
| 186 |
167 |
| 187 /* Remove the old bindings. */ |
|
| 188 g_clear_pointer(&pane->name_binding, g_binding_unbind); |
|
| 189 g_clear_pointer(&pane->topic_binding, g_binding_unbind); |
|
| 190 |
|
| 191 /* Tell the avatar about the new conversation. */ |
|
| 192 pidgin_avatar_set_conversation(PIDGIN_AVATAR(pane->avatar), |
|
| 193 pane->conversation); |
|
| 194 |
|
| 195 if(PURPLE_IS_CONVERSATION(conversation)) { |
|
| 196 pane->name_binding = |
|
| 197 g_object_bind_property(G_OBJECT(conversation), "name", |
|
| 198 G_OBJECT(pane->name), "label", |
|
| 199 G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); |
|
| 200 |
|
| 201 pane->topic_binding = |
|
| 202 g_object_bind_property_full(G_OBJECT(conversation), "topic", |
|
| 203 G_OBJECT(pane->topic), "label", |
|
| 204 G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE, |
|
| 205 pidgin_info_pane_topic_to_label, |
|
| 206 NULL, |
|
| 207 pane, NULL); |
|
| 208 } |
|
| 209 |
|
| 210 /* Notify that we changed. */ |
|
| 211 g_object_notify_by_pspec(G_OBJECT(pane), properties[PROP_CONVERSATION]); |
168 g_object_notify_by_pspec(G_OBJECT(pane), properties[PROP_CONVERSATION]); |
| 212 } |
169 } |