| 446 normal = gtk_icon_set_new(); |
456 normal = gtk_icon_set_new(); |
| 447 if (sized_status_icons[i].translucent_name) |
457 if (sized_status_icons[i].translucent_name) |
| 448 translucent = gtk_icon_set_new(); |
458 translucent = gtk_icon_set_new(); |
| 449 |
459 |
| 450 #define ADD_SIZED_ICON(name, size) if (sized_status_icons[i].name) { \ |
460 #define ADD_SIZED_ICON(name, size) if (sized_status_icons[i].name) { \ |
| 451 add_sized_icon(normal, name, theme, size, sized_status_icons[i], FALSE); \ |
461 add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], FALSE); \ |
| 452 if (sized_status_icons[i].translucent_name) \ |
462 if (sized_status_icons[i].translucent_name) \ |
| 453 add_sized_icon(translucent, name, theme, size, sized_status_icons[i], TRUE); \ |
463 add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], TRUE); \ |
| 454 } |
464 } |
| 455 ADD_SIZED_ICON(microscopic, "11"); |
465 ADD_SIZED_ICON(microscopic, "11"); |
| 456 ADD_SIZED_ICON(extra_small, "16"); |
466 ADD_SIZED_ICON(extra_small, "16"); |
| 457 ADD_SIZED_ICON(small, "22"); |
467 ADD_SIZED_ICON(small, "22"); |
| 458 ADD_SIZED_ICON(medium, "32"); |
468 ADD_SIZED_ICON(medium, "32"); |
| 470 } |
480 } |
| 471 |
481 |
| 472 |
482 |
| 473 gtk_widget_destroy(win); |
483 gtk_widget_destroy(win); |
| 474 g_object_unref(G_OBJECT(icon_factory)); |
484 g_object_unref(G_OBJECT(icon_factory)); |
| |
485 reload_settings(); |
| |
486 } |
| |
487 |
| |
488 void |
| |
489 pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme) |
| |
490 { |
| |
491 GtkIconFactory *icon_factory; |
| |
492 gint i; |
| |
493 GtkWidget *win; |
| |
494 |
| |
495 if (theme != NULL) { |
| |
496 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", |
| |
497 purple_theme_get_name(PURPLE_THEME(theme))); |
| |
498 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", |
| |
499 purple_theme_get_dir(PURPLE_THEME(theme))); |
| |
500 } |
| |
501 else { |
| |
502 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", ""); |
| |
503 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", ""); |
| |
504 } |
| |
505 |
| |
506 icon_factory = gtk_icon_factory_new(); |
| |
507 |
| |
508 gtk_icon_factory_add_default(icon_factory); |
| |
509 |
| |
510 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| |
511 gtk_widget_realize(win); |
| |
512 |
| |
513 /* All non-sized icons */ |
| |
514 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) { |
| |
515 GtkIconSource *source; |
| |
516 GtkIconSet *iconset; |
| |
517 gchar *filename; |
| |
518 |
| |
519 if (stock_icons[i].dir == NULL) { |
| |
520 /* GTK+ Stock icon */ |
| |
521 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), |
| |
522 stock_icons[i].filename); |
| |
523 } else { |
| |
524 filename = find_file(stock_icons[i].dir, stock_icons[i].filename); |
| |
525 |
| |
526 if (filename == NULL) |
| |
527 continue; |
| |
528 |
| |
529 source = gtk_icon_source_new(); |
| |
530 gtk_icon_source_set_filename(source, filename); |
| |
531 gtk_icon_source_set_direction_wildcarded(source, TRUE); |
| |
532 gtk_icon_source_set_size_wildcarded(source, TRUE); |
| |
533 gtk_icon_source_set_state_wildcarded(source, TRUE); |
| |
534 |
| |
535 iconset = gtk_icon_set_new(); |
| |
536 gtk_icon_set_add_source(iconset, source); |
| |
537 |
| |
538 gtk_icon_source_free(source); |
| |
539 g_free(filename); |
| |
540 } |
| |
541 |
| |
542 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); |
| |
543 |
| |
544 gtk_icon_set_unref(iconset); |
| |
545 } |
| |
546 |
| |
547 /* All non-status sized icons */ |
| |
548 for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++) |
| |
549 { |
| |
550 GtkIconSet *iconset = gtk_icon_set_new(); |
| |
551 |
| |
552 #define ADD_SIZED_ICON(name, size) if (sized_stock_icons[i].name) \ |
| |
553 add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE); |
| |
554 ADD_SIZED_ICON(microscopic, "11"); |
| |
555 ADD_SIZED_ICON(extra_small, "16"); |
| |
556 ADD_SIZED_ICON(small, "22"); |
| |
557 ADD_SIZED_ICON(medium, "32"); |
| |
558 ADD_SIZED_ICON(large, "48"); |
| |
559 ADD_SIZED_ICON(huge, "64"); |
| |
560 #undef ADD_SIZED_ICON |
| |
561 |
| |
562 gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset); |
| |
563 gtk_icon_set_unref(iconset); |
| |
564 } |
| |
565 |
| |
566 gtk_widget_destroy(win); |
| |
567 g_object_unref(G_OBJECT(icon_factory)); |
| |
568 reload_settings(); |
| 475 } |
569 } |
| 476 |
570 |
| 477 void |
571 void |
| 478 pidgin_stock_init(void) |
572 pidgin_stock_init(void) |
| 479 { |
573 { |
| 480 GtkIconFactory *icon_factory; |
574 PidginIconThemeLoader *loader, *stockloader; |
| 481 size_t i; |
|
| 482 GtkWidget *win; |
|
| 483 PidginIconThemeLoader *loader; |
|
| 484 const gchar *path = NULL; |
575 const gchar *path = NULL; |
| 485 |
576 |
| 486 if (stock_initted) |
577 if (stock_initted) |
| 487 return; |
578 return; |
| 488 |
579 |
| 492 loader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "status-icon", NULL); |
583 loader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "status-icon", NULL); |
| 493 purple_theme_manager_register_type(PURPLE_THEME_LOADER(loader)); |
584 purple_theme_manager_register_type(PURPLE_THEME_LOADER(loader)); |
| 494 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/status/icon-theme", ""); |
585 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/status/icon-theme", ""); |
| 495 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", ""); |
586 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", ""); |
| 496 |
587 |
| 497 /* Setup the icon factory. */ |
588 stockloader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "stock-icon", NULL); |
| 498 icon_factory = gtk_icon_factory_new(); |
589 purple_theme_manager_register_type(PURPLE_THEME_LOADER(stockloader)); |
| 499 |
590 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", ""); |
| 500 gtk_icon_factory_add_default(icon_factory); |
591 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", ""); |
| 501 |
|
| 502 /* Er, yeah, a hack, but it works. :) */ |
|
| 503 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
|
| 504 gtk_widget_realize(win); |
|
| 505 |
|
| 506 /* All non-sized icons */ |
|
| 507 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) |
|
| 508 { |
|
| 509 GtkIconSource *source; |
|
| 510 GtkIconSet *iconset; |
|
| 511 gchar *filename; |
|
| 512 |
|
| 513 if (stock_icons[i].dir == NULL) |
|
| 514 { |
|
| 515 /* GTK+ Stock icon */ |
|
| 516 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), |
|
| 517 stock_icons[i].filename); |
|
| 518 } |
|
| 519 else |
|
| 520 { |
|
| 521 filename = find_file(stock_icons[i].dir, stock_icons[i].filename); |
|
| 522 |
|
| 523 if (filename == NULL) |
|
| 524 continue; |
|
| 525 |
|
| 526 source = gtk_icon_source_new(); |
|
| 527 gtk_icon_source_set_filename(source, filename); |
|
| 528 gtk_icon_source_set_direction_wildcarded(source, TRUE); |
|
| 529 gtk_icon_source_set_size_wildcarded(source, TRUE); |
|
| 530 gtk_icon_source_set_state_wildcarded(source, TRUE); |
|
| 531 |
|
| 532 iconset = gtk_icon_set_new(); |
|
| 533 gtk_icon_set_add_source(iconset, source); |
|
| 534 |
|
| 535 gtk_icon_source_free(source); |
|
| 536 g_free(filename); |
|
| 537 } |
|
| 538 |
|
| 539 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); |
|
| 540 |
|
| 541 gtk_icon_set_unref(iconset); |
|
| 542 } |
|
| 543 |
592 |
| 544 /* register custom icon sizes */ |
593 /* register custom icon sizes */ |
| 545 microscopic = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC, 11, 11); |
594 microscopic = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC, 11, 11); |
| 546 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16); |
595 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16); |
| 547 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22); |
596 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22); |
| 548 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32); |
597 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32); |
| 549 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48); |
598 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48); |
| 550 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64); |
599 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64); |
| 551 |
600 |
| 552 /* All non-status sized icons */ |
601 pidgin_stock_load_stock_icon_theme(NULL); |
| 553 for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++) |
|
| 554 { |
|
| 555 GtkIconSet *iconset = gtk_icon_set_new(); |
|
| 556 |
|
| 557 #define ADD_SIZED_ICON(name, size) if (sized_stock_icons[i].name) \ |
|
| 558 add_sized_icon(iconset, name, NULL, size, sized_stock_icons[i], FALSE); |
|
| 559 ADD_SIZED_ICON(microscopic, "11"); |
|
| 560 ADD_SIZED_ICON(extra_small, "16"); |
|
| 561 ADD_SIZED_ICON(small, "22"); |
|
| 562 ADD_SIZED_ICON(medium, "32"); |
|
| 563 ADD_SIZED_ICON(large, "48"); |
|
| 564 ADD_SIZED_ICON(huge, "64"); |
|
| 565 #undef ADD_SIZED_ICON |
|
| 566 |
|
| 567 gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset); |
|
| 568 gtk_icon_set_unref(iconset); |
|
| 569 } |
|
| 570 |
|
| 571 gtk_widget_destroy(win); |
|
| 572 g_object_unref(G_OBJECT(icon_factory)); |
|
| 573 |
602 |
| 574 /* Pre-load Status icon theme - this avoids a bug with displaying the correct icon in the tray, theme is destroyed after*/ |
603 /* Pre-load Status icon theme - this avoids a bug with displaying the correct icon in the tray, theme is destroyed after*/ |
| 575 if (purple_prefs_get_string(PIDGIN_PREFS_ROOT "/icon/status/theme") && |
604 if (purple_prefs_get_string(PIDGIN_PREFS_ROOT "/icon/status/theme") && |
| 576 (path = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir"))) { |
605 (path = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir"))) { |
| 577 |
606 |
| 582 } else pidgin_stock_load_status_icon_theme(NULL); |
611 } else pidgin_stock_load_status_icon_theme(NULL); |
| 583 |
612 |
| 584 /* Register the stock items. */ |
613 /* Register the stock items. */ |
| 585 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items)); |
614 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items)); |
| 586 } |
615 } |
| |
616 |
| |
617 static void |
| |
618 pidgin_stock_icon_theme_class_init(PidginStockIconThemeClass *klass) |
| |
619 { |
| |
620 } |
| |
621 |
| |
622 GType |
| |
623 pidgin_stock_icon_theme_get_type(void) |
| |
624 { |
| |
625 static GType type = 0; |
| |
626 if (type == 0) { |
| |
627 static const GTypeInfo info = { |
| |
628 sizeof (PidginStockIconThemeClass), |
| |
629 NULL, /* base_init */ |
| |
630 NULL, /* base_finalize */ |
| |
631 (GClassInitFunc)pidgin_stock_icon_theme_class_init, /* class_init */ |
| |
632 NULL, /* class_finalize */ |
| |
633 NULL, /* class_data */ |
| |
634 sizeof (PidginStockIconTheme), |
| |
635 0, /* n_preallocs */ |
| |
636 NULL, |
| |
637 NULL, /* value table */ |
| |
638 }; |
| |
639 type = g_type_register_static(PIDGIN_TYPE_ICON_THEME, |
| |
640 "PidginStockIconTheme", &info, 0); |
| |
641 } |
| |
642 return type; |
| |
643 } |