Mercurial > pidgin
comparison src/gtknotify.c @ 11359:9480e0d0f563
[gaim-migrate @ 13581]
Search results notification extended so that any column can be added.
committer: Tailor Script <tailor@pidgin.im>
author | Bartoz Oler <bartosz@pidgin.im> |
---|---|
date | Sun, 28 Aug 2005 22:21:24 +0000 |
parents | b9b9b67f6325 |
children | c9b815aeddc1 |
comparison
equal
deleted
inserted
replaced
11358:fb702c34794b | 11359:9480e0d0f563 |
---|---|
54 GtkWidget *treeview; | 54 GtkWidget *treeview; |
55 GtkWidget *window; | 55 GtkWidget *window; |
56 | 56 |
57 } GaimNotifySearchResultsData; | 57 } GaimNotifySearchResultsData; |
58 | 58 |
59 enum | 59 typedef struct |
60 { | 60 { |
61 COLUMN_ICON, | 61 GaimNotifySearchButton *button; |
62 COLUMN_SCREENNAME, | 62 GaimNotifySearchResultsData *data; |
63 NUM_COLUMNS | 63 |
64 }; | 64 } GaimNotifySearchResultsButtonData; |
65 | 65 |
66 static void *gaim_gtk_notify_emails(size_t count, gboolean detailed, | 66 static void *gaim_gtk_notify_emails(size_t count, gboolean detailed, |
67 const char **subjects, | 67 const char **subjects, |
68 const char **froms, const char **tos, | 68 const char **froms, const char **tos, |
69 const char **urls, GCallback cb, | 69 const char **urls, GCallback cb, |
95 { | 95 { |
96 gaim_notify_close(GAIM_NOTIFY_SEARCHRESULTS, data); | 96 gaim_notify_close(GAIM_NOTIFY_SEARCHRESULTS, data); |
97 } | 97 } |
98 | 98 |
99 static void | 99 static void |
100 add_buddy_helper_cb(GtkWidget *widget, GaimNotifySearchResultsData *data) | 100 searchresults_callback_wrapper_cb(GtkWidget *widget, GaimNotifySearchResultsButtonData *bd) |
101 { | 101 { |
102 GaimNotifySearchResultsData *data = bd->data; | |
103 | |
102 GtkTreeSelection *selection; | 104 GtkTreeSelection *selection; |
103 GtkTreeModel *model; | 105 GtkTreeModel *model; |
104 GtkTreeIter iter; | 106 GtkTreeIter iter; |
105 gchar *buddy; | 107 GaimNotifySearchButton *button; |
108 GList *row = NULL; | |
109 gchar *str; | |
110 int i; | |
106 | 111 |
107 g_return_if_fail(data != NULL); | 112 g_return_if_fail(data != NULL); |
108 | 113 |
109 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->treeview)); | 114 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->treeview)); |
110 | 115 |
111 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | 116 if (gtk_tree_selection_get_selected(selection, &model, &iter)) |
112 { | 117 { |
113 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, | 118 for (i = 1; i < gtk_tree_model_get_n_columns(GTK_TREE_MODEL(model)); i++) { |
114 COLUMN_SCREENNAME, &buddy, -1); | 119 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, i, &str, -1); |
115 gaim_blist_request_add_buddy(data->account, buddy, NULL, NULL); | 120 row = g_list_append(row, str); |
116 g_free(buddy); | 121 } |
117 } | 122 } |
123 | |
124 button = bd->button; | |
125 button->callback(gaim_account_get_connection(data->account), row); | |
118 } | 126 } |
119 | 127 |
120 static void * | 128 static void * |
121 gaim_gtk_notify_message(GaimNotifyMsgType type, const char *title, | 129 gaim_gtk_notify_message(GaimNotifyMsgType type, const char *title, |
122 const char *primary, const char *secondary, | 130 const char *primary, const char *secondary, |
424 gtk_widget_show(window); | 432 gtk_widget_show(window); |
425 | 433 |
426 return window; | 434 return window; |
427 } | 435 } |
428 | 436 |
437 static void | |
438 gaim_gtk_notify_searchresults_new_rows(GaimConnection *gc, GaimNotifySearchResults *results, | |
439 void *data_, void *user_data) | |
440 { | |
441 GaimNotifySearchResultsData *data = data_; | |
442 GtkListStore *model = data->model; | |
443 GtkTreeIter iter; | |
444 GdkPixbuf *icon, *scaled; | |
445 int col_num; | |
446 int i, j; | |
447 | |
448 gtk_list_store_clear(data->model); | |
449 | |
450 icon = gaim_gtk_create_prpl_icon(gaim_connection_get_account(gc)); | |
451 scaled = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); | |
452 | |
453 /* +1 is for the automagically created Status column. */ | |
454 col_num = gaim_notify_searchresults_get_columns_count(results) + 1; | |
455 | |
456 for (i = 0; i < gaim_notify_searchresults_get_rows_count(results); i++) { | |
457 GList *row = gaim_notify_searchresults_row_get(results, i); | |
458 | |
459 gtk_list_store_append(model, &iter); | |
460 gtk_list_store_set(model, &iter, 0, scaled, -1); | |
461 | |
462 for (j = 1; j < col_num; j++) { | |
463 GValue v = {0, }; | |
464 char *escaped = g_markup_escape_text(g_list_nth_data(row, j - 1), -1); | |
465 | |
466 g_value_init(&v, G_TYPE_STRING); | |
467 g_value_set_string(&v, escaped); | |
468 gtk_list_store_set_value(model, &iter, j, &v); | |
469 g_free(escaped); | |
470 } | |
471 } | |
472 } | |
473 | |
429 static void * | 474 static void * |
430 gaim_gtk_notify_searchresults(GaimConnection *gc, const char *title, | 475 gaim_gtk_notify_searchresults(GaimConnection *gc, const char *title, |
431 const char *primary, const char *secondary, | 476 const char *primary, const char *secondary, |
432 const char **results, GCallback cb, | 477 GaimNotifySearchResults *results, GCallback cb, |
433 void *user_data) | 478 void *user_data) |
434 { | 479 { |
435 GtkWidget *window; | 480 GtkWidget *window; |
481 GtkWidget *treeview; | |
482 GtkWidget *button, *close_button; | |
483 GType *col_types; | |
484 GtkListStore *model; | |
485 GtkCellRenderer *renderer; | |
486 int col_num; | |
487 int i; | |
488 GList *buttons = NULL; | |
489 | |
436 GtkWidget *vbox; | 490 GtkWidget *vbox; |
437 GtkWidget *button_area; | 491 GtkWidget *button_area; |
438 GtkWidget *label; | 492 GtkWidget *label; |
439 GtkWidget *close_button; | |
440 GtkWidget *add_button; | |
441 GtkWidget *sw; | 493 GtkWidget *sw; |
442 GtkWidget *treeview; | |
443 GdkPixbuf *icon, *scaled; | |
444 GaimNotifySearchResultsData *data; | 494 GaimNotifySearchResultsData *data; |
445 GtkListStore *model; | |
446 GtkCellRenderer *renderer; | |
447 GtkTreeIter iter; | |
448 int i; | |
449 char *label_text; | 495 char *label_text; |
450 char *primary_esc, *secondary_esc; | 496 char *primary_esc, *secondary_esc; |
451 | 497 |
452 data = g_malloc(sizeof(GaimNotifySearchResultsData)); | 498 data = g_malloc(sizeof(GaimNotifySearchResultsData)); |
453 | 499 |
481 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 527 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
482 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | 528 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
483 gtk_widget_show(label); | 529 gtk_widget_show(label); |
484 g_free(label_text); | 530 g_free(label_text); |
485 | 531 |
532 /* +1 is for the automagically created Status column. */ | |
533 col_num = gaim_notify_searchresults_get_columns_count(results) + 1; | |
534 | |
486 /* Setup the list model */ | 535 /* Setup the list model */ |
487 model = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING); | 536 col_types = g_new0(GType, col_num); |
537 | |
538 /* There always is this first column. */ | |
539 col_types[0] = GDK_TYPE_PIXBUF; | |
540 for (i = 1; i < col_num; i++) { | |
541 col_types[i] = G_TYPE_STRING; | |
542 } | |
543 model = gtk_list_store_newv(col_num, col_types); | |
488 | 544 |
489 /* Setup the scrolled window containing the treeview */ | 545 /* Setup the scrolled window containing the treeview */ |
490 sw = gtk_scrolled_window_new(NULL, NULL); | 546 sw = gtk_scrolled_window_new(NULL, NULL); |
491 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | 547 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), |
492 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | 548 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
496 gtk_widget_show(sw); | 552 gtk_widget_show(sw); |
497 | 553 |
498 /* Setup the treeview */ | 554 /* Setup the treeview */ |
499 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | 555 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); |
500 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | 556 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); |
501 gtk_widget_set_size_request(treeview, 250, 150); | 557 gtk_widget_set_size_request(treeview, 500, 400); |
502 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), | 558 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), |
503 GTK_SELECTION_SINGLE); | 559 GTK_SELECTION_SINGLE); |
504 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | 560 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); |
505 gtk_container_add(GTK_CONTAINER(sw), treeview); | 561 gtk_container_add(GTK_CONTAINER(sw), treeview); |
506 gtk_widget_show(treeview); | 562 gtk_widget_show(treeview); |
507 | 563 |
508 /* icon column */ | 564 renderer = gtk_cell_renderer_pixbuf_new(); |
509 renderer = gtk_cell_renderer_pixbuf_new (); | |
510 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), | 565 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), |
511 -1, "Icon", renderer, | 566 -1, "", renderer, "pixbuf", 0, NULL); |
512 "pixbuf", COLUMN_ICON, | 567 |
513 NULL); | 568 for (i = 1; i < col_num; i++) { |
514 | 569 renderer = gtk_cell_renderer_text_new(); |
515 /* screenname column */ | 570 |
516 renderer = gtk_cell_renderer_text_new(); | 571 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, |
517 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), | 572 gaim_notify_searchresults_column_get_title(results, i-1), |
518 -1, "Screenname", renderer, | 573 renderer, "text", i, NULL); |
519 "text", COLUMN_SCREENNAME, | 574 } |
520 NULL); | 575 |
521 | |
522 /* Setup the button area */ | 576 /* Setup the button area */ |
523 button_area = gtk_hbutton_box_new(); | 577 button_area = gtk_hbutton_box_new(); |
524 gtk_box_pack_start(GTK_BOX(vbox), button_area, FALSE, FALSE, 0); | 578 gtk_box_pack_start(GTK_BOX(vbox), button_area, FALSE, FALSE, 0); |
525 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_area), GTK_BUTTONBOX_END); | 579 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_area), GTK_BUTTONBOX_END); |
526 gtk_box_set_spacing(GTK_BOX(button_area), GAIM_HIG_BORDER); | 580 gtk_box_set_spacing(GTK_BOX(button_area), GAIM_HIG_BORDER); |
527 gtk_widget_show(button_area); | 581 gtk_widget_show(button_area); |
528 | 582 |
529 /* Add the Add button */ | 583 for (i = 0; i < g_list_length(results->buttons); i++) { |
530 add_button = gtk_button_new_from_stock(GTK_STOCK_ADD); | 584 GaimNotifySearchButton *b = g_list_nth_data(results->buttons, i); |
531 gtk_box_pack_start(GTK_BOX(button_area), add_button, FALSE, FALSE, 0); | 585 button = NULL; |
532 gtk_widget_show(add_button); | 586 switch (b->type) { |
587 case GAIM_NOTIFY_BUTTON_CONTINUE: | |
588 button = gtk_button_new_from_stock(GTK_STOCK_GO_FORWARD); | |
589 break; | |
590 case GAIM_NOTIFY_BUTTON_ADD_BUDDY: | |
591 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
592 break; | |
593 default: | |
594 gaim_debug_warning("gtknotify", "Incorrect button type: %d\n", b->type); | |
595 } | |
596 if (button != NULL) { | |
597 gtk_box_pack_start(GTK_BOX(button_area), button, FALSE, FALSE, 0); | |
598 gtk_widget_show(button); | |
599 buttons = g_list_append(buttons, button); | |
600 } | |
601 } | |
533 | 602 |
534 /* Add the Close button */ | 603 /* Add the Close button */ |
535 close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | 604 close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); |
536 gtk_box_pack_start(GTK_BOX(button_area), close_button, FALSE, FALSE, 0); | 605 gtk_box_pack_start(GTK_BOX(button_area), close_button, FALSE, FALSE, 0); |
537 gtk_widget_show(close_button); | 606 gtk_widget_show(close_button); |
538 | 607 |
539 /* Add the buddies to the tree view */ | |
540 icon = gaim_gtk_create_prpl_icon(gc->account); | |
541 scaled = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); | |
542 | |
543 for (i = 0; results[i] != NULL; i++) | |
544 { | |
545 char *escaped = g_markup_escape_text(results[i], -1); | |
546 gtk_list_store_append(model, &iter); | |
547 gtk_list_store_set(model, &iter, | |
548 COLUMN_ICON, scaled, | |
549 COLUMN_SCREENNAME, escaped, | |
550 -1); | |
551 g_free(escaped); | |
552 } | |
553 | |
554 data->account = gc->account; | 608 data->account = gc->account; |
555 data->model = model; | 609 data->model = model; |
556 data->treeview = treeview; | 610 data->treeview = treeview; |
557 data->window = window; | 611 data->window = window; |
558 | 612 |
613 /* Insert rows. */ | |
614 gaim_gtk_notify_searchresults_new_rows(gc, results, data, NULL); | |
615 | |
559 /* Connect Signals */ | 616 /* Connect Signals */ |
560 g_signal_connect(G_OBJECT(add_button), "clicked", | 617 for (i = 0; i < g_list_length(results->buttons); i++) { |
561 G_CALLBACK(add_buddy_helper_cb), data); | 618 GaimNotifySearchResultsButtonData *bd = g_new0(GaimNotifySearchResultsButtonData, 1); |
619 bd->button = g_list_nth_data(results->buttons, i); | |
620 bd->data = data; | |
621 g_signal_connect(G_OBJECT(g_list_nth_data(buttons, i)), "clicked", | |
622 G_CALLBACK(searchresults_callback_wrapper_cb), bd); | |
623 } | |
624 | |
562 g_signal_connect_swapped(G_OBJECT(close_button), "clicked", | 625 g_signal_connect_swapped(G_OBJECT(close_button), "clicked", |
563 G_CALLBACK(searchresults_close_cb), data); | 626 G_CALLBACK(searchresults_close_cb), data); |
564 | 627 |
565 /* Show the window */ | 628 /* Show the window */ |
566 gtk_widget_show(window); | 629 gtk_widget_show(window); |
809 gaim_gtk_notify_message, | 872 gaim_gtk_notify_message, |
810 gaim_gtk_notify_email, | 873 gaim_gtk_notify_email, |
811 gaim_gtk_notify_emails, | 874 gaim_gtk_notify_emails, |
812 gaim_gtk_notify_formatted, | 875 gaim_gtk_notify_formatted, |
813 gaim_gtk_notify_searchresults, | 876 gaim_gtk_notify_searchresults, |
877 gaim_gtk_notify_searchresults_new_rows, | |
814 gaim_gtk_notify_userinfo, | 878 gaim_gtk_notify_userinfo, |
815 gaim_gtk_notify_uri, | 879 gaim_gtk_notify_uri, |
816 gaim_gtk_close_notify | 880 gaim_gtk_close_notify |
817 }; | 881 }; |
818 | 882 |