Mercurial > pidgin
comparison src/gtkstatusbox.c @ 11732:03c813a42c76
[gaim-migrate @ 14023]
here's what iw as working on, with the bits that activiate it commented out.
its not finished at all, but i'm tired of people breaking it ;)
hopefully this will motivate me to finish it tonight/tomorrow.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Sun, 23 Oct 2005 01:42:01 +0000 |
parents | 8a981a601242 |
children | 992d49cf2b92 |
comparison
equal
deleted
inserted
replaced
11731:d9aab67a9e07 | 11732:03c813a42c76 |
---|---|
25 | 25 |
26 #include "account.h" | 26 #include "account.h" |
27 #include "internal.h" | 27 #include "internal.h" |
28 #include "savedstatuses.h" | 28 #include "savedstatuses.h" |
29 #include "status.h" | 29 #include "status.h" |
30 #include "debug.h" | |
30 | 31 |
31 #include "gtkgaim.h" | 32 #include "gtkgaim.h" |
32 #include "gtksavedstatuses.h" | 33 #include "gtksavedstatuses.h" |
33 #include "gtkstock.h" | 34 #include "gtkstock.h" |
34 #include "gtkstatusbox.h" | 35 #include "gtkstatusbox.h" |
35 | 36 |
36 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); | 37 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); |
37 static void remove_typing_cb(GtkGaimStatusBox *box); | 38 static void remove_typing_cb(GtkGaimStatusBox *box); |
38 | 39 |
40 static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box); | |
39 static void gtk_gaim_status_box_changed(GtkComboBox *box); | 41 static void gtk_gaim_status_box_changed(GtkComboBox *box); |
40 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | 42 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); |
41 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | 43 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); |
42 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | 44 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); |
43 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | 45 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); |
115 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | 117 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); |
116 | 118 |
117 switch (param_id) { | 119 switch (param_id) { |
118 case PROP_ACCOUNT: | 120 case PROP_ACCOUNT: |
119 statusbox->account = g_value_get_pointer(value); | 121 statusbox->account = g_value_get_pointer(value); |
122 gtk_gaim_status_box_regenerate(statusbox); | |
120 break; | 123 break; |
121 default: | 124 default: |
122 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | 125 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); |
123 break; | 126 break; |
124 } | 127 } |
214 gtk_tree_path_free(path); | 217 gtk_tree_path_free(path); |
215 | 218 |
216 g_free(text); | 219 g_free(text); |
217 } | 220 } |
218 | 221 |
222 static GdkPixbuf * | |
223 load_icon(const char *basename) | |
224 { | |
225 char basename2[BUFSIZ]; | |
226 char *filename; | |
227 GdkPixbuf *pixbuf, *scale = NULL; | |
228 | |
229 if (!strcmp(basename, "available")) | |
230 basename = "online"; | |
231 else if (!strcmp(basename, "hidden")) | |
232 basename = "invisible"; | |
233 | |
234 /* | |
235 * TODO: Find a way to fallback to the GaimStatusPrimitive | |
236 * if an icon for this id does not exist. | |
237 */ | |
238 g_snprintf(basename2, sizeof(basename2), "%s.png", | |
239 basename); | |
240 | |
241 | |
242 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", | |
243 basename2, NULL); | |
244 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
245 g_free(filename); | |
246 | |
247 if (pixbuf != NULL) { | |
248 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
249 GDK_INTERP_BILINEAR); | |
250 | |
251 g_object_unref(G_OBJECT(pixbuf)); | |
252 } else { | |
253 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
254 "default", basename, NULL); | |
255 scale = gdk_pixbuf_new_from_file(filename, NULL); | |
256 g_free(filename); | |
257 } | |
258 | |
259 return scale; | |
260 } | |
261 | |
262 static void | |
263 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) | |
264 { | |
265 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; | |
266 GtkIconSize icon_size; | |
267 const char *current_savedstatus_name; | |
268 GaimSavedStatus *saved_status; | |
269 | |
270 | |
271 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
272 | |
273 gtk_list_store_clear(status_box->dropdown_store); | |
274 | |
275 if (!(GTK_GAIM_STATUS_BOX(status_box)->account)) { | |
276 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_ONLINE, | |
277 icon_size, "GtkGaimStatusBox"); | |
278 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_AWAY, | |
279 icon_size, "GtkGaimStatusBox"); | |
280 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
281 icon_size, "GtkGaimStatusBox"); | |
282 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_INVISIBLE, | |
283 icon_size, "GtkGaimStatusBox"); | |
284 /* hacks */ | |
285 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Available"), NULL, "available"); | |
286 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf2, _("Away"), NULL, "away"); | |
287 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf4, _("Invisible"), NULL, "invisible"); | |
288 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf3, _("Offline"), NULL, "offline"); | |
289 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Custom..."), NULL, "custom"); | |
290 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Saved..."), NULL, "saved"); | |
291 | |
292 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); | |
293 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
294 if (saved_status == NULL) | |
295 { | |
296 /* Default to "available" */ | |
297 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
298 } | |
299 else | |
300 { | |
301 GaimStatusPrimitive primitive; | |
302 const char *message; | |
303 | |
304 primitive = gaim_savedstatus_get_type(saved_status); | |
305 if (gaim_savedstatus_has_substatuses(saved_status) || | |
306 ((primitive != GAIM_STATUS_AVAILABLE) && | |
307 (primitive != GAIM_STATUS_OFFLINE) && | |
308 (primitive != GAIM_STATUS_AWAY) && | |
309 (primitive != GAIM_STATUS_HIDDEN))) | |
310 { | |
311 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 4); | |
312 } | |
313 else | |
314 { | |
315 if (primitive == GAIM_STATUS_AVAILABLE) | |
316 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
317 if (primitive == GAIM_STATUS_OFFLINE) | |
318 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
319 else if (primitive == GAIM_STATUS_AWAY) | |
320 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
321 else if (primitive == GAIM_STATUS_HIDDEN) | |
322 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
323 } | |
324 | |
325 message = gaim_savedstatus_get_message(saved_status); | |
326 if (message != NULL) | |
327 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); | |
328 } | |
329 | |
330 | |
331 } else { | |
332 const GList *l; | |
333 for (l = gaim_account_get_status_types(GTK_GAIM_STATUS_BOX(status_box)->account); l != NULL; l = l->next) { | |
334 GaimStatusType *status_type = (GaimStatusType *)l->data; | |
335 | |
336 if (!gaim_status_type_is_user_settable(status_type)) | |
337 continue; | |
338 | |
339 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), load_icon(gaim_status_type_get_id(status_type)), | |
340 gaim_status_type_get_name(status_type), | |
341 NULL, | |
342 gaim_status_type_get_id(status_type)); | |
343 | |
344 } | |
345 } | |
346 | |
347 } | |
348 | |
219 static void | 349 static void |
220 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) | 350 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
221 { | 351 { |
222 GtkCellRenderer *text_rend; | 352 GtkCellRenderer *text_rend; |
223 GtkCellRenderer *icon_rend; | 353 GtkCellRenderer *icon_rend; |
224 GtkTextBuffer *buffer; | 354 GtkTextBuffer *buffer; |
225 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; | 355 GtkTreePath *path; |
226 GtkIconSize icon_size; | 356 GtkIconSize icon_size; |
227 GtkTreePath *path; | |
228 const char *current_savedstatus_name; | |
229 GaimSavedStatus *saved_status; | |
230 | 357 |
231 text_rend = gtk_cell_renderer_text_new(); | 358 text_rend = gtk_cell_renderer_text_new(); |
232 icon_rend = gtk_cell_renderer_pixbuf_new(); | 359 icon_rend = gtk_cell_renderer_pixbuf_new(); |
233 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | 360 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); |
234 | 361 |
296 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | 423 status_box->sw = gtk_scrolled_window_new(NULL, NULL); |
297 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | 424 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
298 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | 425 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); |
299 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | 426 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); |
300 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | 427 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); |
301 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_ONLINE, | 428 |
302 icon_size, "GtkGaimStatusBox"); | 429 gtk_gaim_status_box_regenerate(status_box); |
303 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_AWAY, | |
304 icon_size, "GtkGaimStatusBox"); | |
305 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
306 icon_size, "GtkGaimStatusBox"); | |
307 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_INVISIBLE, | |
308 icon_size, "GtkGaimStatusBox"); | |
309 /* hacks */ | |
310 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Available"), NULL, "available"); | |
311 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf2, _("Away"), NULL, "away"); | |
312 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf4, _("Invisible"), NULL, "invisible"); | |
313 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf3, _("Offline"), NULL, "offline"); | |
314 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Custom..."), NULL, "custom"); | |
315 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Saved..."), NULL, "saved"); | |
316 | |
317 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); | |
318 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
319 if (saved_status == NULL) | |
320 { | |
321 /* Default to "available" */ | |
322 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
323 } | |
324 else | |
325 { | |
326 GaimStatusPrimitive primitive; | |
327 const char *message; | |
328 | |
329 primitive = gaim_savedstatus_get_type(saved_status); | |
330 if (gaim_savedstatus_has_substatuses(saved_status) || | |
331 ((primitive != GAIM_STATUS_AVAILABLE) && | |
332 (primitive != GAIM_STATUS_OFFLINE) && | |
333 (primitive != GAIM_STATUS_AWAY) && | |
334 (primitive != GAIM_STATUS_HIDDEN))) | |
335 { | |
336 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 4); | |
337 } | |
338 else | |
339 { | |
340 if (primitive == GAIM_STATUS_AVAILABLE) | |
341 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
342 if (primitive == GAIM_STATUS_OFFLINE) | |
343 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
344 else if (primitive == GAIM_STATUS_AWAY) | |
345 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
346 else if (primitive == GAIM_STATUS_HIDDEN) | |
347 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
348 } | |
349 | |
350 message = gaim_savedstatus_get_message(saved_status); | |
351 if (message != NULL) | |
352 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); | |
353 } | |
354 } | 430 } |
355 | 431 |
356 | 432 |
357 static void | 433 static void |
358 gtk_gaim_status_box_size_request(GtkWidget *widget, | 434 gtk_gaim_status_box_size_request(GtkWidget *widget, |
432 { | 508 { |
433 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | 509 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); |
434 } | 510 } |
435 | 511 |
436 void | 512 void |
437 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GdkPixbuf *pixbuf, const char *text, const char *sec_text, char *edit) | 513 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GdkPixbuf *pixbuf, const char *text, const char *sec_text, const char *edit) |
438 { | 514 { |
439 GtkTreeIter iter; | 515 GtkTreeIter iter; |
440 char *t; | 516 char *t; |
441 | 517 |
442 if (sec_text) { | 518 if (sec_text) { |