Mercurial > pidgin.yaz
comparison src/gtkconn.c @ 7506:240aca6344b6
[gaim-migrate @ 8119]
I'm going climbing soon, but I'll be around later to make Mandrake
9.1 RPMs. 9.2 ISOs haven't been released to the public yet, AFAIK.
This is some more disconnection dialog stuff from Daniel Atallah.
It fixes a memleak (that I think I introduced), makes the most
recently disconnected account the selected account, and makes the
window manager close work correctly.
datallah: The fix for the window-manager-close-button is the
"case GTK_RESPONSE_DELETE_EVENT:" line.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 13 Nov 2003 23:57:45 +0000 |
parents | 39185ff57842 |
children | 83453431d722 |
comparison
equal
deleted
inserted
replaced
7505:d29c2f50ac24 | 7506:240aca6344b6 |
---|---|
290 GtkTreeModel *model = NULL; | 290 GtkTreeModel *model = NULL; |
291 GaimAccount *account = NULL; | 291 GaimAccount *account = NULL; |
292 GaimConnection *gc = NULL; | 292 GaimConnection *gc = NULL; |
293 | 293 |
294 switch(id) { | 294 switch(id) { |
295 case GTK_RESPONSE_DELETE_EVENT: | |
295 case GTK_RESPONSE_CLOSE: | 296 case GTK_RESPONSE_CLOSE: |
296 disconnect_window_hide(); | 297 disconnect_window_hide(); |
297 break; | 298 break; |
298 case GTK_RESPONSE_ACCEPT: | 299 case GTK_RESPONSE_ACCEPT: |
299 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); | 300 model = gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview)); |
347 static void | 348 static void |
348 gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) | 349 gaim_gtk_connection_report_disconnect(GaimConnection *gc, const char *text) |
349 { | 350 { |
350 char *label_text = NULL; | 351 char *label_text = NULL; |
351 GdkPixbuf *scale, *icon; | 352 GdkPixbuf *scale, *icon; |
352 GtkTreeViewColumn *col; | 353 GtkTreeIter new_row_iter, iter; |
353 GtkListStore *list_store; | |
354 GtkTreeIter iter; | |
355 GValue val = { 0, }; | 354 GValue val = { 0, }; |
356 GaimAccount *account = NULL; | 355 GaimAccount *account = NULL; |
357 gboolean multiple_disconnected = FALSE; | 356 GtkListStore *list_store; |
358 | 357 GtkTreeViewColumn *col; |
359 /* Make sure we have a list_store */ | 358 GtkTreeSelection *sel = NULL; |
360 if (!disconnect_window || !disconnect_window->treeview) | 359 |
360 label_text = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s has been disconnected.</span>\n\n%s\n%s", | |
361 gaim_account_get_username(gaim_connection_get_account(gc)), gaim_date_full(), | |
362 text ? text : _("Reason Unknown.")); | |
363 | |
364 /* Build the window if it isn't there yet */ | |
365 if (!disconnect_window) { | |
366 GtkWidget *hbox, *vbox, *img; | |
367 GtkCellRenderer *rend, *rend2; | |
368 | |
369 disconnect_window = g_new0(struct disconnect_window, 1); | |
370 disconnect_window->window = gtk_dialog_new_with_buttons("", NULL, GTK_DIALOG_NO_SEPARATOR, | |
371 _("Reconnect"), GTK_RESPONSE_ACCEPT, | |
372 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); | |
373 g_signal_connect(G_OBJECT(disconnect_window->window), "response", G_CALLBACK(disconnect_response_cb), disconnect_window); | |
374 | |
375 gtk_container_set_border_width(GTK_CONTAINER(disconnect_window->window), 6); | |
376 gtk_window_set_resizable(GTK_WINDOW(disconnect_window->window), FALSE); | |
377 gtk_dialog_set_has_separator(GTK_DIALOG(disconnect_window->window), FALSE); | |
378 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(disconnect_window->window)->vbox), 12); | |
379 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), 6); | |
380 | |
381 hbox = gtk_hbox_new(FALSE, 12); | |
382 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), hbox); | |
383 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); | |
384 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
385 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
386 | |
387 vbox = gtk_vbox_new(FALSE, 12); | |
388 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
389 | |
390 disconnect_window->label = gtk_label_new(label_text); | |
391 | |
392 gtk_label_set_line_wrap(GTK_LABEL(disconnect_window->label), TRUE); | |
393 gtk_misc_set_alignment(GTK_MISC(disconnect_window->label), 0, 0); | |
394 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->label, FALSE, FALSE, 0); | |
395 | |
396 gtk_widget_show_all(disconnect_window->window); | |
397 | |
398 /* Tree View */ | |
399 disconnect_window->sw = gtk_scrolled_window_new(NULL,NULL); | |
400 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_SHADOW_IN); | |
401 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
402 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->sw, TRUE, TRUE, 0); | |
403 | |
361 list_store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); | 404 list_store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); |
362 else | 405 disconnect_window->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL(list_store)); |
406 | |
407 rend = gtk_cell_renderer_pixbuf_new(); | |
408 rend2 = gtk_cell_renderer_text_new(); | |
409 col = gtk_tree_view_column_new(); | |
410 gtk_tree_view_column_set_title(col, _("Account")); | |
411 gtk_tree_view_column_pack_start(col, rend, FALSE); | |
412 gtk_tree_view_column_pack_start(col, rend2, FALSE); | |
413 gtk_tree_view_column_set_attributes(col, rend, "pixbuf", 0, NULL); | |
414 gtk_tree_view_column_set_attributes(col, rend2, "text", 1, NULL); | |
415 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
416 | |
417 rend = gtk_cell_renderer_text_new(); | |
418 col = gtk_tree_view_column_new_with_attributes (_("Time"), | |
419 rend, "text", 2, NULL); | |
420 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
421 | |
422 g_object_unref(G_OBJECT(list_store)); | |
423 gtk_container_add(GTK_CONTAINER(disconnect_window->sw), disconnect_window->treeview); | |
424 | |
425 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (disconnect_window->treeview)); | |
426 gtk_widget_set_size_request(disconnect_window->treeview, -1, 96); | |
427 g_signal_connect (G_OBJECT (sel), "changed", | |
428 G_CALLBACK (disconnect_tree_cb), list_store); | |
429 } else | |
363 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview))); | 430 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(disconnect_window->treeview))); |
364 | 431 |
365 /* If this account is already in our list then remove it */ | 432 /* If this account is already in our list then remove it */ |
366 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)) { | 433 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)) { |
367 do { | 434 do { |
373 break; | 440 break; |
374 } | 441 } |
375 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)); | 442 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)); |
376 } | 443 } |
377 | 444 |
378 label_text = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s has been disconnected.</span>\n\n%s\n%s", | |
379 gaim_account_get_username(gaim_connection_get_account(gc)), gaim_date_full(), | |
380 text ? text : _("Reason Unknown.")); | |
381 | |
382 /* Add this account to our list of disconnected accounts */ | 445 /* Add this account to our list of disconnected accounts */ |
383 icon = create_prpl_icon(gaim_connection_get_account(gc)); | 446 icon = create_prpl_icon(gaim_connection_get_account(gc)); |
384 scale = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); | 447 scale = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); |
385 gtk_list_store_append(list_store, &iter); | 448 gtk_list_store_append(list_store, &new_row_iter); |
386 gtk_list_store_set(list_store, &iter, | 449 gtk_list_store_set(list_store, &new_row_iter, |
387 0, scale, | 450 0, scale, |
388 1, gaim_account_get_username(gaim_connection_get_account(gc)), | 451 1, gaim_account_get_username(gaim_connection_get_account(gc)), |
389 2, gaim_date_full(), | 452 2, gaim_date_full(), |
390 3, label_text, | 453 3, label_text, |
391 4, gaim_connection_get_account(gc), -1); | 454 4, gaim_connection_get_account(gc), -1); |
392 g_object_unref(G_OBJECT(icon)); | 455 g_object_unref(G_OBJECT(icon)); |
393 g_object_unref(G_OBJECT(scale)); | 456 g_object_unref(G_OBJECT(scale)); |
394 | 457 |
395 /* Check how many disconnected accounts we have */ | |
396 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)) | 458 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)) |
459 { | |
460 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(disconnect_window->treeview)); | |
461 gtk_tree_selection_select_iter(sel, &new_row_iter); | |
462 /* if we have more than one disconnected acct, display the treeview */ | |
397 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)) | 463 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)) |
398 multiple_disconnected = TRUE; | 464 gtk_widget_show_all(disconnect_window->sw); |
399 | |
400 if (!disconnect_window || !multiple_disconnected) { | |
401 GtkWidget *hbox, *vbox, *img; | |
402 GtkCellRenderer *rend, *rend2; | |
403 GtkTreeSelection *sel; | |
404 | |
405 disconnect_window = g_new0(struct disconnect_window, 1); | |
406 disconnect_window->window = gtk_dialog_new_with_buttons("", NULL, GTK_DIALOG_NO_SEPARATOR, | |
407 _("Reconnect"), GTK_RESPONSE_ACCEPT, | |
408 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); | |
409 g_signal_connect(G_OBJECT(disconnect_window->window), "response", G_CALLBACK(disconnect_response_cb), disconnect_window); | |
410 | |
411 gtk_container_set_border_width(GTK_CONTAINER(disconnect_window->window), 6); | |
412 gtk_window_set_resizable(GTK_WINDOW(disconnect_window->window), FALSE); | |
413 gtk_dialog_set_has_separator(GTK_DIALOG(disconnect_window->window), FALSE); | |
414 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(disconnect_window->window)->vbox), 12); | |
415 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), 6); | |
416 | |
417 hbox = gtk_hbox_new(FALSE, 12); | |
418 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(disconnect_window->window)->vbox), hbox); | |
419 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); | |
420 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
421 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
422 | |
423 vbox = gtk_vbox_new(FALSE, 12); | |
424 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | |
425 | |
426 disconnect_window->label = gtk_label_new(NULL); | |
427 | |
428 gtk_label_set_markup(GTK_LABEL(disconnect_window->label), label_text); | |
429 gtk_label_set_line_wrap(GTK_LABEL(disconnect_window->label), TRUE); | |
430 gtk_misc_set_alignment(GTK_MISC(disconnect_window->label), 0, 0); | |
431 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->label, FALSE, FALSE, 0); | |
432 | |
433 gtk_widget_show_all(disconnect_window->window); | |
434 | |
435 /* Tree View */ | |
436 disconnect_window->sw = gtk_scrolled_window_new(NULL,NULL); | |
437 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_SHADOW_IN); | |
438 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(disconnect_window->sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | |
439 gtk_box_pack_start(GTK_BOX(vbox), disconnect_window->sw, TRUE, TRUE, 0); | |
440 | |
441 disconnect_window->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL(list_store)); | |
442 | |
443 rend = gtk_cell_renderer_pixbuf_new(); | |
444 rend2 = gtk_cell_renderer_text_new(); | |
445 col = gtk_tree_view_column_new(); | |
446 gtk_tree_view_column_set_title(col, _("Account")); | |
447 gtk_tree_view_column_pack_start(col, rend, FALSE); | |
448 gtk_tree_view_column_pack_start(col, rend2, FALSE); | |
449 gtk_tree_view_column_set_attributes(col, rend, "pixbuf", 0, NULL); | |
450 gtk_tree_view_column_set_attributes(col, rend2, "text", 1, NULL); | |
451 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
452 | |
453 rend = gtk_cell_renderer_text_new(); | |
454 col = gtk_tree_view_column_new_with_attributes (_("Time"), | |
455 rend, "text", 2, NULL); | |
456 gtk_tree_view_append_column (GTK_TREE_VIEW(disconnect_window->treeview), col); | |
457 | |
458 g_object_unref(G_OBJECT(list_store)); | |
459 gtk_container_add(GTK_CONTAINER(disconnect_window->sw), disconnect_window->treeview); | |
460 | |
461 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (disconnect_window->treeview)); | |
462 gtk_widget_set_size_request(disconnect_window->treeview, -1, 96); | |
463 g_signal_connect (G_OBJECT (sel), "changed", | |
464 G_CALLBACK (disconnect_tree_cb), list_store); | |
465 } else { | |
466 gtk_label_set_markup(GTK_LABEL(disconnect_window->label), label_text); | |
467 gtk_widget_show_all(disconnect_window->sw); | |
468 } | 465 } |
469 | 466 |
470 g_free(label_text); | 467 g_free(label_text); |
471 gtk_window_present(GTK_WINDOW(disconnect_window->window)); | 468 gtk_window_present(GTK_WINDOW(disconnect_window->window)); |
472 } | 469 } |