Mercurial > pidgin.yaz
comparison pidgin/pidginstock.c @ 26817:3912f55a1633
propagate from branch 'im.pidgin.pidgin' (head fbb4fe5da444943eecc76bdcd6c8ba967790b6c8)
to branch 'im.pidgin.cpw.darkrain42.xmpp.bosh' (head 601bc627c9430320848361f0ed81c6c4c6ee53e0)
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Tue, 28 Apr 2009 18:43:57 +0000 |
parents | c13c256c56c0 |
children | e6ba07a72fd8 4548c114e953 |
comparison
equal
deleted
inserted
replaced
26743:de9816c970fe | 26817:3912f55a1633 |
---|---|
318 } | 318 } |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 static gchar * | 322 static gchar * |
323 find_icon_file(PidginStatusIconTheme *theme, const gchar *size, SizedStockIcon sized_icon, gboolean rtl) | 323 find_icon_file(PidginIconTheme *theme, const gchar *size, SizedStockIcon sized_icon, gboolean rtl) |
324 { | 324 { |
325 const gchar *file, *dir; | 325 const gchar *file, *dir; |
326 gchar *file_full = NULL; | 326 gchar *file_full = NULL; |
327 gchar *tmp; | 327 gchar *tmp; |
328 | 328 |
350 g_free(tmp); | 350 g_free(tmp); |
351 return file_full; | 351 return file_full; |
352 } | 352 } |
353 | 353 |
354 static void | 354 static void |
355 add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginStatusIconTheme *theme, | 355 add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginIconTheme *theme, |
356 const char *size, SizedStockIcon sized_icon, gboolean translucent) | 356 const char *size, SizedStockIcon sized_icon, gboolean translucent) |
357 { | 357 { |
358 char *filename; | 358 char *filename; |
359 GtkIconSource *source; | 359 GtkIconSource *source; |
360 GdkPixbuf *pixbuf; | 360 GdkPixbuf *pixbuf; |
407 g_object_unref(pixbuf); | 407 g_object_unref(pixbuf); |
408 gtk_icon_source_free(source); | 408 gtk_icon_source_free(source); |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
412 static void | |
413 reload_settings(void) | |
414 { | |
415 #if GTK_CHECK_VERSION(2,4,0) | |
416 GtkSettings *setting = NULL; | |
417 setting = gtk_settings_get_default(); | |
418 gtk_rc_reset_styles(setting); | |
419 #endif | |
420 } | |
421 | |
412 /***************************************************************************** | 422 /***************************************************************************** |
413 * Public API functions | 423 * Public API functions |
414 *****************************************************************************/ | 424 *****************************************************************************/ |
415 | 425 |
416 void | 426 void |
445 normal = gtk_icon_set_new(); | 455 normal = gtk_icon_set_new(); |
446 if (sized_status_icons[i].translucent_name) | 456 if (sized_status_icons[i].translucent_name) |
447 translucent = gtk_icon_set_new(); | 457 translucent = gtk_icon_set_new(); |
448 | 458 |
449 #define ADD_SIZED_ICON(name, size) if (sized_status_icons[i].name) { \ | 459 #define ADD_SIZED_ICON(name, size) if (sized_status_icons[i].name) { \ |
450 add_sized_icon(normal, name, theme, size, sized_status_icons[i], FALSE); \ | 460 add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], FALSE); \ |
451 if (sized_status_icons[i].translucent_name) \ | 461 if (sized_status_icons[i].translucent_name) \ |
452 add_sized_icon(translucent, name, theme, size, sized_status_icons[i], TRUE); \ | 462 add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], TRUE); \ |
453 } | 463 } |
454 ADD_SIZED_ICON(microscopic, "11"); | 464 ADD_SIZED_ICON(microscopic, "11"); |
455 ADD_SIZED_ICON(extra_small, "16"); | 465 ADD_SIZED_ICON(extra_small, "16"); |
456 ADD_SIZED_ICON(small, "22"); | 466 ADD_SIZED_ICON(small, "22"); |
457 ADD_SIZED_ICON(medium, "32"); | 467 ADD_SIZED_ICON(medium, "32"); |
469 } | 479 } |
470 | 480 |
471 | 481 |
472 gtk_widget_destroy(win); | 482 gtk_widget_destroy(win); |
473 g_object_unref(G_OBJECT(icon_factory)); | 483 g_object_unref(G_OBJECT(icon_factory)); |
484 reload_settings(); | |
485 } | |
486 | |
487 void | |
488 pidgin_stock_load_stock_icon_theme(PidginStockIconTheme *theme) | |
489 { | |
490 GtkIconFactory *icon_factory; | |
491 gint i; | |
492 GtkWidget *win; | |
493 | |
494 if (theme != NULL) { | |
495 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", | |
496 purple_theme_get_name(PURPLE_THEME(theme))); | |
497 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", | |
498 purple_theme_get_dir(PURPLE_THEME(theme))); | |
499 } | |
500 else { | |
501 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", ""); | |
502 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", ""); | |
503 } | |
504 | |
505 icon_factory = gtk_icon_factory_new(); | |
506 | |
507 gtk_icon_factory_add_default(icon_factory); | |
508 | |
509 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
510 gtk_widget_realize(win); | |
511 | |
512 /* All non-sized icons */ | |
513 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) { | |
514 GtkIconSource *source; | |
515 GtkIconSet *iconset; | |
516 gchar *filename; | |
517 | |
518 if (stock_icons[i].dir == NULL) { | |
519 /* GTK+ Stock icon */ | |
520 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), | |
521 stock_icons[i].filename); | |
522 } else { | |
523 filename = find_file(stock_icons[i].dir, stock_icons[i].filename); | |
524 | |
525 if (filename == NULL) | |
526 continue; | |
527 | |
528 source = gtk_icon_source_new(); | |
529 gtk_icon_source_set_filename(source, filename); | |
530 gtk_icon_source_set_direction_wildcarded(source, TRUE); | |
531 gtk_icon_source_set_size_wildcarded(source, TRUE); | |
532 gtk_icon_source_set_state_wildcarded(source, TRUE); | |
533 | |
534 iconset = gtk_icon_set_new(); | |
535 gtk_icon_set_add_source(iconset, source); | |
536 | |
537 gtk_icon_source_free(source); | |
538 g_free(filename); | |
539 } | |
540 | |
541 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); | |
542 | |
543 gtk_icon_set_unref(iconset); | |
544 } | |
545 | |
546 /* All non-status sized icons */ | |
547 for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++) | |
548 { | |
549 GtkIconSet *iconset = gtk_icon_set_new(); | |
550 | |
551 #define ADD_SIZED_ICON(name, size) if (sized_stock_icons[i].name) \ | |
552 add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE); | |
553 ADD_SIZED_ICON(microscopic, "11"); | |
554 ADD_SIZED_ICON(extra_small, "16"); | |
555 ADD_SIZED_ICON(small, "22"); | |
556 ADD_SIZED_ICON(medium, "32"); | |
557 ADD_SIZED_ICON(large, "48"); | |
558 ADD_SIZED_ICON(huge, "64"); | |
559 #undef ADD_SIZED_ICON | |
560 | |
561 gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset); | |
562 gtk_icon_set_unref(iconset); | |
563 } | |
564 | |
565 gtk_widget_destroy(win); | |
566 g_object_unref(G_OBJECT(icon_factory)); | |
567 reload_settings(); | |
474 } | 568 } |
475 | 569 |
476 void | 570 void |
477 pidgin_stock_init(void) | 571 pidgin_stock_init(void) |
478 { | 572 { |
479 GtkIconFactory *icon_factory; | 573 PidginIconThemeLoader *loader, *stockloader; |
480 size_t i; | |
481 GtkWidget *win; | |
482 PidginIconThemeLoader *loader; | |
483 const gchar *path = NULL; | 574 const gchar *path = NULL; |
484 | 575 |
485 if (stock_initted) | 576 if (stock_initted) |
486 return; | 577 return; |
487 | 578 |
491 loader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "status-icon", NULL); | 582 loader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "status-icon", NULL); |
492 purple_theme_manager_register_type(PURPLE_THEME_LOADER(loader)); | 583 purple_theme_manager_register_type(PURPLE_THEME_LOADER(loader)); |
493 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/status/icon-theme", ""); | 584 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/status/icon-theme", ""); |
494 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", ""); | 585 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir", ""); |
495 | 586 |
496 /* Setup the icon factory. */ | 587 stockloader = g_object_new(PIDGIN_TYPE_ICON_THEME_LOADER, "type", "stock-icon", NULL); |
497 icon_factory = gtk_icon_factory_new(); | 588 purple_theme_manager_register_type(PURPLE_THEME_LOADER(stockloader)); |
498 | 589 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/stock/icon-theme", ""); |
499 gtk_icon_factory_add_default(icon_factory); | 590 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/stock/icon-theme-dir", ""); |
500 | |
501 /* Er, yeah, a hack, but it works. :) */ | |
502 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
503 gtk_widget_realize(win); | |
504 | |
505 /* All non-sized icons */ | |
506 for (i = 0; i < G_N_ELEMENTS(stock_icons); i++) | |
507 { | |
508 GtkIconSource *source; | |
509 GtkIconSet *iconset; | |
510 gchar *filename; | |
511 | |
512 if (stock_icons[i].dir == NULL) | |
513 { | |
514 /* GTK+ Stock icon */ | |
515 iconset = gtk_style_lookup_icon_set(gtk_widget_get_style(win), | |
516 stock_icons[i].filename); | |
517 } | |
518 else | |
519 { | |
520 filename = find_file(stock_icons[i].dir, stock_icons[i].filename); | |
521 | |
522 if (filename == NULL) | |
523 continue; | |
524 | |
525 source = gtk_icon_source_new(); | |
526 gtk_icon_source_set_filename(source, filename); | |
527 gtk_icon_source_set_direction_wildcarded(source, TRUE); | |
528 gtk_icon_source_set_size_wildcarded(source, TRUE); | |
529 gtk_icon_source_set_state_wildcarded(source, TRUE); | |
530 | |
531 iconset = gtk_icon_set_new(); | |
532 gtk_icon_set_add_source(iconset, source); | |
533 | |
534 gtk_icon_source_free(source); | |
535 g_free(filename); | |
536 } | |
537 | |
538 gtk_icon_factory_add(icon_factory, stock_icons[i].name, iconset); | |
539 | |
540 gtk_icon_set_unref(iconset); | |
541 } | |
542 | 591 |
543 /* register custom icon sizes */ | 592 /* register custom icon sizes */ |
544 microscopic = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC, 11, 11); | 593 microscopic = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC, 11, 11); |
545 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16); | 594 extra_small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL, 16, 16); |
546 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22); | 595 small = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_SMALL, 22, 22); |
547 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32); | 596 medium = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_MEDIUM, 32, 32); |
548 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48); | 597 large = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_LARGE, 48, 48); |
549 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64); | 598 huge = gtk_icon_size_register(PIDGIN_ICON_SIZE_TANGO_HUGE, 64, 64); |
550 | 599 |
551 /* All non-status sized icons */ | 600 pidgin_stock_load_stock_icon_theme(NULL); |
552 for (i = 0; i < G_N_ELEMENTS(sized_stock_icons); i++) | |
553 { | |
554 GtkIconSet *iconset = gtk_icon_set_new(); | |
555 | |
556 #define ADD_SIZED_ICON(name, size) if (sized_stock_icons[i].name) \ | |
557 add_sized_icon(iconset, name, NULL, size, sized_stock_icons[i], FALSE); | |
558 ADD_SIZED_ICON(microscopic, "11"); | |
559 ADD_SIZED_ICON(extra_small, "16"); | |
560 ADD_SIZED_ICON(small, "22"); | |
561 ADD_SIZED_ICON(medium, "32"); | |
562 ADD_SIZED_ICON(large, "48"); | |
563 ADD_SIZED_ICON(huge, "64"); | |
564 #undef ADD_SIZED_ICON | |
565 | |
566 gtk_icon_factory_add(icon_factory, sized_stock_icons[i].name, iconset); | |
567 gtk_icon_set_unref(iconset); | |
568 } | |
569 | |
570 gtk_widget_destroy(win); | |
571 g_object_unref(G_OBJECT(icon_factory)); | |
572 | 601 |
573 /* Pre-load Status icon theme - this avoids a bug with displaying the correct icon in the tray, theme is destroyed after*/ | 602 /* Pre-load Status icon theme - this avoids a bug with displaying the correct icon in the tray, theme is destroyed after*/ |
574 if (purple_prefs_get_string(PIDGIN_PREFS_ROOT "/icon/status/theme") && | 603 if (purple_prefs_get_string(PIDGIN_PREFS_ROOT "/icon/status/theme") && |
575 (path = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir"))) { | 604 (path = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/status/icon-theme-dir"))) { |
576 | 605 |
581 } else pidgin_stock_load_status_icon_theme(NULL); | 610 } else pidgin_stock_load_status_icon_theme(NULL); |
582 | 611 |
583 /* Register the stock items. */ | 612 /* Register the stock items. */ |
584 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items)); | 613 gtk_stock_add_static(stock_items, G_N_ELEMENTS(stock_items)); |
585 } | 614 } |
615 | |
616 static void | |
617 pidgin_stock_icon_theme_class_init(PidginStockIconThemeClass *klass) | |
618 { | |
619 } | |
620 | |
621 GType | |
622 pidgin_stock_icon_theme_get_type(void) | |
623 { | |
624 static GType type = 0; | |
625 if (type == 0) { | |
626 static const GTypeInfo info = { | |
627 sizeof (PidginStockIconThemeClass), | |
628 NULL, /* base_init */ | |
629 NULL, /* base_finalize */ | |
630 (GClassInitFunc)pidgin_stock_icon_theme_class_init, /* class_init */ | |
631 NULL, /* class_finalize */ | |
632 NULL, /* class_data */ | |
633 sizeof (PidginStockIconTheme), | |
634 0, /* n_preallocs */ | |
635 NULL, | |
636 NULL, /* value table */ | |
637 }; | |
638 type = g_type_register_static(PIDGIN_TYPE_ICON_THEME, | |
639 "PidginStockIconTheme", &info, 0); | |
640 } | |
641 return type; | |
642 } |