aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/public/images/token_icons/metal.png
blob: d8a8c33ec87d34d9d82cd3f072d9fe350d6990dc (plain) (blame)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 80 00 00 00 80 08 03 00 00 00 f4 e0 91 .PNG........IHDR................
0020 f9 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 .....gAMA......a.....sRGB.......
0040 02 49 50 4c 54 45 ff ff ff 25 23 24 23 21 22 fb fb fb fc fc fc fd fd fd 16 14 15 21 1f 20 fe fe .IPLTE...%#$#!"............!....
0060 fe 24 22 23 b3 b2 b2 9e 9d 9e 10 0e 0f 5c 5c 5c 15 14 14 5e 5e 5e 14 14 14 ae ae ae 14 15 15 23 .$"#.........\\\...^^^.........#
0080 22 22 15 13 14 11 0f 10 5c 5b 5b 5e 5c 5d 5e 5c 5e ad ad ad 15 12 14 fa fa fa fb fa fb 19 17 18 ""......\[[^\]^\^...............
00a0 22 1f 20 5d 5b 5c 22 20 21 26 24 25 15 15 15 af ad ae 1c 1a 1b f1 f1 f1 ed ec ed 25 22 23 23 22 "..][\".!&$%...............%"##"
00c0 23 fa f9 f9 43 41 42 14 12 13 28 26 27 d3 d1 d2 ff fe fe 5d 5d 5d 5f 5d 5e a8 a6 a7 24 21 22 fa #...CAB...(&'......]]]_]^...$!".
00e0 f9 fa fe fc fd 46 44 45 b2 b2 b2 08 06 07 f8 f8 f8 f9 f9 f9 24 23 24 12 10 11 5d 5c 5c 1f 1b 1c .....FDE............$#$...]\\...
0100 34 32 32 16 13 15 26 23 24 25 24 24 37 38 38 04 02 03 85 85 85 83 83 83 fd fc fc fd fc fd fe fd 422...&#$%$$788.................
0120 fe ff fe ff e4 e4 e4 16 16 16 5f 5f 5f 61 61 61 f1 f0 f1 ce cf ce c1 c0 c1 fc fb fb d1 d0 d1 fc ..........___aaa................
0140 fb fc d2 d1 d2 b0 af b0 78 78 78 24 21 23 e4 e3 e4 3a 37 39 cf ce cf 17 14 16 ae ac ad fd fe fd ........xxx$!#...:79............
0160 45 43 44 46 43 45 aa a8 a9 c6 c6 c6 0e 0c 0d 0d 0c 0d 1c 19 1b a4 a3 a3 79 77 78 39 38 39 ac aa ECDFCE..................ywx989..
0180 ab 17 16 16 f3 f3 f3 57 57 57 44 42 43 b0 ad ae 52 52 52 61 5f 60 fe fd fd 5a 58 59 21 1e 20 0c .......WWWDBC...RRRa_`...ZXY!...
01a0 0a 0b a8 a7 a8 f7 f7 f7 f0 f0 f0 a9 a9 a9 f0 ef f0 a2 a2 a2 39 37 38 16 15 15 08 08 08 17 15 16 ....................978.........
01c0 16 15 16 25 25 25 27 24 25 19 16 17 6d 6d 6d 99 98 98 17 18 18 35 32 34 b5 b5 b5 ee ee ee 29 29 ...%%%'$%...mmm......524......))
01e0 29 1d 1b 1c ab ab ab eb ea eb fb fa fa b3 b3 b3 60 5d 5e 37 34 35 23 1f 20 37 35 36 0d 0b 0c 69 )...............`]^745#..756...i
0200 69 69 d4 d4 d4 aa aa aa 2c 2d 2c ec eb ec 58 57 57 3b 3b 3b 12 0e 10 58 58 58 22 1e 1f 0b 09 0a ii......,-,...XWW;;;...XXX".....
0220 a0 a0 a0 19 19 19 7d 7d 7d 22 22 22 a5 a3 a4 c8 c8 c8 0f 0f 0f 3a 3a 3a ac ac ac 0f 0d 0f 9e 9e ......}}}""".........:::........
0240 9e 1f 1d 1e 60 5e 5f 20 1e 1f 13 10 11 21 20 20 12 12 12 84 84 84 04 04 04 84 83 84 7e 7c 7d 62 ....`^_......!..............~|}b
0260 60 61 86 84 85 16 13 14 fb f9 fa 51 4f 50 26 26 26 84 82 83 13 13 13 7a 7a 7a a5 a5 a5 97 97 97 `a.........QOP&&&......zzz......
0280 53 51 52 7d 7c 7d 28 28 28 00 00 00 10 0e 10 3a 72 f2 14 00 00 02 64 49 44 41 54 78 da ed d8 77 SQR}|}(((......:r.....dIDATx...w
02a0 73 d3 30 18 80 f1 d7 8e 65 2b 50 48 0b 49 19 b6 d3 a4 0d 94 24 2d a5 7b d1 42 17 7b ef bd f7 de s.0.....e+PH.I......$-.{.B.{....
02c0 7b b7 ec bd f7 de 7b ef cd 27 43 25 77 a5 77 e9 71 17 3b 48 85 bc cf df 96 fc 3b 39 39 5b 02 c0 {.....{..'C%w.w.q.;H......;99[..
02e0 30 0c c3 30 0c c3 30 0c c3 b0 ff b7 9e 71 98 83 12 87 ce 2a 29 55 2c dc bf c0 c8 37 de 18 7a 29 0..0..0......q.....*)U,....7..z)
0300 b1 05 b0 31 b6 20 0e 2b 40 e0 d3 d7 da ba ba da 8f 37 21 66 ca 0a 7a e3 c5 ab f7 cf 9f 5e 3b 05 ...1...+@........7!f..z......^;.
0320 c4 06 e0 4b 4d f8 47 52 f2 f7 cf e0 88 79 05 e0 6d 4d d8 e3 79 f2 ec 0e 28 36 00 2f cd 2c 49 fa ...KM.GR.....y..mM..y...(6./.,I.
0340 f6 e1 8a 15 c0 03 36 b6 ea dd d5 c3 b6 00 47 5e 67 7a bd 65 b7 ee 59 01 a4 b9 9d da e3 eb e9 45 ......6.......G^gz.e..Y........E
0360 b6 00 ae 64 a7 a6 49 49 6d ad 00 da b5 67 63 65 b5 0d 02 10 10 77 00 21 fd 09 21 0a 15 05 68 ba ...d..IIm....gce.....w.!..!...h.
0380 f1 00 31 00 4a 07 0d 1f 95 3d 26 7b d2 30 22 08 00 43 d3 7b 68 9a 53 1d fb e7 89 ff 22 20 a7 11 ..1.J....=&{.0"..C.{h.S....."...
03a0 20 ab 53 84 01 86 0c 2e f3 f9 c6 4f ce 10 06 70 45 56 40 1c a0 33 7b c9 68 1d 3b a4 b4 2a 00 8d ..S........O...pEV@..3{.h.;..*..
03c0 24 0a 40 a9 d8 15 a0 64 ea 86 b3 dd 59 07 d7 fe a6 70 05 28 70 32 eb 68 65 e5 f1 aa a2 e6 d7 71 $.@....d....Y....p.(p2.he......q
03e0 7c 04 0e b8 78 e1 52 45 c5 b1 13 a7 05 01 14 e8 dd 47 f2 f9 fc e5 cd 7f 17 7c 01 a9 5d 1b af f3 |...x.RE.........G.......|..]...
0400 74 41 00 02 b8 00 3a 21 40 38 40 95 11 d0 02 80 ed a2 fb 72 03 38 5b 1f 20 f2 32 7a 94 22 0c 70 tA....:!@8@........r.8[...2z.".p
0420 ee ee fd 40 e0 e1 e5 03 5c 5e c7 51 00 ea 80 5d 67 6e 57 57 9f df b7 47 0c 80 6d 57 17 ad eb c6 ...@....\^.Q...]gnWW...G..mW....
0440 da 5b c2 e5 93 2c 1a d0 74 9e 48 81 07 20 2d ea 6f c8 f9 b3 bc 25 00 d7 cf 72 04 08 07 a4 6e 96 .[...,..t.H...-.o....%...r....n.
0460 57 79 f3 04 ee 8e 73 1a b6 e7 65 ee d8 b9 54 18 60 d9 96 6d 61 f7 d6 e2 19 c2 00 33 37 ae cf cd Wy....s...e...T.`..ma......37...
0480 5d 33 77 02 d0 84 3d a8 54 7e 25 ec a0 12 cf 8a 11 80 00 be 80 5e ee 44 07 2c 57 fd b2 ec 2f b7 ]3w...=.T~%..........^.D.,W.../.
04a0 04 70 2d 64 63 25 d3 1e 60 e5 ea 80 69 ee 2f ae 8f 1d 40 60 f1 ec 39 a6 19 98 95 61 0b 30 6f 53 .p-dc%..`...i./...@`..9....a.0oS
04c0 61 28 54 b8 7b 41 ec 93 10 18 37 7f 7a 68 c9 b4 89 23 a0 9f 65 00 0c 1c 19 34 8c 43 7a 70 b4 25 a(T.{A....7.zh...#..e....4.Czp.%
04e0 7e be 61 e8 41 1d fe f1 a2 36 1c 9c c6 62 18 86 61 18 86 61 18 86 61 58 e2 f4 13 a4 b1 92 94 62 ~.a.A....6...b..a..a..aX.......b
0500 36 e5 52 00 00 00 00 49 45 4e 44 ae 42 60 82 6.R....IEND.B`.
/a> 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* msg-composer-hdrs.c
 *
 * Copyright (C) 1999 Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * published by the Free Software Foundation; either version 2 of the
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ettore Perazzoli
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>

#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-widget.h>

#include <gtk/gtkmenuitem.h>
#include <gtk/gtkoptionmenu.h>
#include <gtk/gtktooltips.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libgnome/gnome-i18n.h>
#include <libedataserverui/e-name-selector.h>

#include "Composer.h"

#include <gtk/gtkmenuitem.h>
#include <gtk/gtkoptionmenu.h>
#include <gtk/gtktooltips.h>
#include <gtk/gtkentry.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkmessagedialog.h>

#include <gconf/gconf.h>
#include <gconf/gconf-client.h>

#include <gal/e-text/e-entry.h>

#include "widgets/misc/e-error.h"

#include <camel/camel.h>
#include "e-msg-composer-hdrs.h"
#include "mail/mail-config.h"
/*#include "mail/em-folder-selection-button.h"*/
#include "mail/em-folder-selector.h"
#include "mail/mail-component.h"
#include "mail/em-folder-tree.h"



/* Indexes in the GtkTable assigned to various items */

#define LINE_FROM    0
#define LINE_REPLYTO 1
#define LINE_TO      2
#define LINE_CC      3
#define LINE_BCC     4
#define LINE_POSTTO  5
#define LINE_SUBJECT 6


typedef struct {
    GtkWidget *label;
    GtkWidget *entry;
} EMsgComposerHdrPair;

struct _EMsgComposerHdrsPrivate {
    ENameSelector *name_selector;
    
    /* ui component */
    BonoboUIComponent *uic;
    
    /* The tooltips.  */
    GtkTooltips *tooltips;
    
    EAccountList *accounts;
    GSList *from_options;
    
    gboolean post_custom;
    
    /* Standard headers.  */
    EMsgComposerHdrPair from, reply_to, to, cc, bcc, post_to, subject;
};


static GtkTableClass *parent_class = NULL;

enum {
    SHOW_ADDRESS_DIALOG,
    SUBJECT_CHANGED,
    HDRS_CHANGED,
    FROM_CHANGED,
    LAST_SIGNAL
};

static int signals[LAST_SIGNAL];


static void
addressbook_dialog_response (ENameSelectorDialog *name_selector_dialog, gint response, gpointer user_data)
{
    EMsgComposerHdrs *hdrs = E_MSG_COMPOSER_HDRS (user_data);

    gtk_widget_hide (GTK_WIDGET (name_selector_dialog));
}

static void
setup_name_selector (EMsgComposerHdrs *hdrs)
{
    EMsgComposerHdrsPrivate *priv;
    ENameSelectorDialog *name_selector_dialog;
    
    priv = hdrs->priv;
    
    g_assert (priv->name_selector == NULL);

    priv->name_selector = e_name_selector_new ();
    name_selector_dialog = e_name_selector_peek_dialog (priv->name_selector);
    g_signal_connect (name_selector_dialog, "response",
              G_CALLBACK (addressbook_dialog_response), hdrs);
}

typedef struct {
    EMsgComposerHdrs *hdrs;
    char *string;
} EMsgComposerHdrsAndString;

static void
e_msg_composer_hdrs_and_string_free (EMsgComposerHdrsAndString *emchas)
{
    if (emchas->hdrs)
        g_object_unref (emchas->hdrs);
    g_free (emchas->string);
    g_free (emchas);
}

static EMsgComposerHdrsAndString *
e_msg_composer_hdrs_and_string_create (EMsgComposerHdrs *hdrs, const char *string)
{
    EMsgComposerHdrsAndString *emchas;
    
    emchas = g_new (EMsgComposerHdrsAndString, 1);
    emchas->hdrs = hdrs;
    emchas->string = g_strdup (string);
    if (emchas->hdrs)
        g_object_ref (emchas->hdrs);
    
    return emchas;
}

static void
address_button_clicked_cb (GtkButton *button, gpointer data)
{
    EMsgComposerHdrsAndString *emchas;
    EMsgComposerHdrs *hdrs;
    EMsgComposerHdrsPrivate *priv;
    ENameSelectorDialog *name_selector_dialog;
    
    emchas = data;
    hdrs = emchas->hdrs;
    priv = hdrs->priv;

    name_selector_dialog = e_name_selector_peek_dialog (priv->name_selector);
    gtk_widget_show (GTK_WIDGET (name_selector_dialog));
}

static void
from_changed (GtkWidget *item, gpointer data)
{
    EMsgComposerHdrs *hdrs = E_MSG_COMPOSER_HDRS (data);
    const char *reply_to;
    GList *post_items = NULL;
    
    /* this will retrieve items relative to the previous account */
    if (!hdrs->priv->post_custom)
        post_items = e_msg_composer_hdrs_get_post_to(hdrs);
    
    hdrs->account = g_object_get_data ((GObject *) item, "account");
    
    /* we do this rather than calling e_msg_composer_hdrs_set_reply_to()
       because we don't want to change the visibility of the header */
    reply_to = hdrs->account->id->reply_to;
    gtk_entry_set_text (GTK_ENTRY (hdrs->priv->reply_to.entry), reply_to ? reply_to : "");
    
    /* folders should be made relative to the new from */
    if (!hdrs->priv->post_custom) {
        e_msg_composer_hdrs_set_post_to_list (hdrs, post_items);
        g_list_foreach (post_items, (GFunc)g_free, NULL);
        g_list_free(post_items);
    }
    
    g_signal_emit (hdrs, signals [FROM_CHANGED], 0);
}

static void
account_added_cb (EAccountList *accounts, EAccount *account, EMsgComposerHdrs *hdrs)
{
    GtkWidget *item, *menu, *omenu, *toplevel;
    char *label;
    
    omenu = e_msg_composer_hdrs_get_from_omenu (hdrs);
    menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu));
    
    label = g_strdup_printf ("%s <%s>", account->id->name, account->id->address);
    item = gtk_menu_item_new_with_label (label);
    gtk_widget_show (item);
    g_free (label);
    
    g_object_ref (account);
    g_object_set_data ((GObject *) item, "account", account);
    g_signal_connect (item, "activate", G_CALLBACK (from_changed), hdrs);
    
    /* this is so we can later set which one we want */
    hdrs->priv->from_options = g_slist_append (hdrs->priv->from_options, item);
    
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
    
    toplevel = gtk_widget_get_toplevel ((GtkWidget *) hdrs);
    gtk_widget_set_sensitive (toplevel, TRUE);
}

static void
account_changed_cb (EAccountList *accounts, EAccount *account, EMsgComposerHdrs *hdrs)
{
    GtkWidget *item, *label;
    EAccount *acnt;
    GSList *node;
    char *text;
    
    node = hdrs->priv->from_options;
    while (node != NULL) {
        item = node->data;
        acnt = g_object_get_data ((GObject *) item, "account");
        if (acnt == account) {
            text = g_strdup_printf ("%s <%s>", account->id->name, account->id->address);
            label = gtk_bin_get_child ((GtkBin *) item);
            gtk_label_set_text ((GtkLabel *) label, text);
            g_free (text);
            break;
        }
        
        node = node->next;
    }
}

static void
account_removed_cb (EAccountList *accounts, EAccount *account, EMsgComposerHdrs *hdrs)
{
    struct _EMsgComposerHdrsPrivate *priv = hdrs->priv;
    GtkWidget *item, *omenu, *toplevel;
    EAccount *acnt;
    GSList *node;
    
    node = priv->from_options;
    while (node != NULL) {
        item = node->data;
        acnt = g_object_get_data ((GObject *) item, "account");
        if (acnt == account) {
            if (hdrs->account == account)
                hdrs->account = NULL;
            
            priv->from_options = g_slist_remove_link (priv->from_options, node);
            g_slist_free_1 (node);
            g_object_unref (account);
            gtk_widget_destroy (item);
            break;
        }
        
        node = node->next;
    }
    
    if (hdrs->account == NULL) {
        if (priv->from_options) {
            /* the previously selected account was removed,
               default the new selection to the first account in
               the menu list */
            omenu = e_msg_composer_hdrs_get_from_omenu (hdrs);
            
            item = priv->from_options->data;
            gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), 0);
            g_signal_emit_by_name (item, "activate", hdrs);
        } else {
            toplevel = gtk_widget_get_toplevel ((GtkWidget *) hdrs);
            gtk_widget_set_sensitive (toplevel, FALSE);
            
            /* FIXME: this should offer a 'configure account' button, can we do that? */
            e_error_run((GtkWindow *)toplevel, "mail-composer:all-accounts-deleted", NULL);
        }
    }
}

static GtkWidget *
create_from_optionmenu (EMsgComposerHdrs *hdrs)
{
    struct _EMsgComposerHdrsPrivate *priv = hdrs->priv;
    GtkWidget *hbox, *omenu, *menu, *item, *first = NULL;
    int i = 0, history = 0, m, matches;
    GPtrArray *addresses;
    GConfClient *gconf;
    EAccount *account;
    EIterator *iter;
    char *uid;
    
    omenu = gtk_option_menu_new ();
    menu = gtk_menu_new ();
    
    gconf = gconf_client_get_default ();
    uid = gconf_client_get_string (gconf, "/apps/evolution/mail/default_account", NULL);
    g_object_unref (gconf);
    
    /* Make list of account email addresses */
    addresses = g_ptr_array_new ();
    iter = e_list_get_iterator ((EList *) priv->accounts);
    while (e_iterator_is_valid (iter)) {
        account = (EAccount *) e_iterator_get (iter);
        
        if (account->id->address)
            g_ptr_array_add (addresses, account->id->address);
        
        e_iterator_next (iter);
    }
    
    e_iterator_reset (iter);
    
    while (e_iterator_is_valid (iter)) {
        char *label;
        
        account = (EAccount *) e_iterator_get (iter);
        
        /* this should never ever fail */
        if (!account || !account->name || !account->id) {
            g_assert_not_reached ();
            continue;
        }
        
        if (account->id->address && *account->id->address) {
            /* If the account has a unique email address, just
             * show that. Otherwise include the account name.
             */
            for (m = matches = 0; m < addresses->len; m++) {
                if (!strcmp (account->id->address, addresses->pdata[m]))
                    matches++;
            }
            
            if (matches > 1)
                label = g_strdup_printf ("%s <%s> (%s)", account->id->name,
                             account->id->address, account->name);
            else
                label = g_strdup_printf ("%s <%s>", account->id->name, account->id->address);
            
            item = gtk_menu_item_new_with_label (label);
            g_free (label);
            
            g_object_ref (account);
            g_object_set_data ((GObject *) item, "account", account);
            g_signal_connect (item, "activate", G_CALLBACK (from_changed), hdrs);
            
            if (uid && !strcmp (account->uid, uid)) {
                first = item;
                history = i;
            }
            
            /* this is so we can later set which one we want */
            hdrs->priv->from_options = g_slist_append (hdrs->priv->from_options, item);
            
            gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
            gtk_widget_show (item);
            i++;
        }
        
        e_iterator_next (iter);
    }
    
    g_free (uid);
    g_object_unref (iter);
    
    g_ptr_array_free (addresses, TRUE);
    
    gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
    
    if (first) {
        gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), history);
        g_signal_emit_by_name (first, "activate", hdrs);
    }
    
    hbox = gtk_hbox_new (FALSE, 6);
    gtk_box_pack_start_defaults (GTK_BOX (hbox), omenu);
    gtk_widget_show (omenu);
    gtk_widget_show (hbox);
    
    g_object_set_data ((GObject *) hbox, "from_menu", omenu);
    
    /* listen for changes to the account list so we can auto-update the from menu */
    g_signal_connect (priv->accounts, "account-added", G_CALLBACK (account_added_cb), hdrs);
    g_signal_connect (priv->accounts, "account-changed", G_CALLBACK (account_changed_cb), hdrs);
    g_signal_connect (priv->accounts, "account-removed", G_CALLBACK (account_removed_cb), hdrs);
    
    return hbox;
}

static void
addressbook_entry_changed (GtkWidget *entry,
               gpointer   user_data)
{
    EMsgComposerHdrs *hdrs = E_MSG_COMPOSER_HDRS (user_data);
    
    g_signal_emit (hdrs, signals[HDRS_CHANGED], 0);
}

static GtkWidget *
create_addressbook_entry (EMsgComposerHdrs *hdrs, const char *name)
{
    EMsgComposerHdrsPrivate *priv;
    ENameSelectorModel *name_selector_model;
    ENameSelectorEntry *name_selector_entry;
    
    priv = hdrs->priv;

    name_selector_model = e_name_selector_peek_model (priv->name_selector);
    e_name_selector_model_add_section (name_selector_model, name, name, NULL);

    name_selector_entry = e_name_selector_peek_section_entry (priv->name_selector, name);
    g_signal_connect (name_selector_entry, "changed",
              G_CALLBACK (addressbook_entry_changed), hdrs);

    return GTK_WIDGET (name_selector_entry);

#if 0

    CORBA_exception_init (&ev);
    
    GNOME_Evolution_Addressbook_SelectNames_addSection (
        corba_select_names, name, name, &ev);
    if (ev._major != CORBA_NO_EXCEPTION) {
        CORBA_exception_free (&ev);
        return NULL;
    }
    
    corba_control =
        GNOME_Evolution_Addressbook_SelectNames_getEntryBySection (
            corba_select_names, name, &ev);
    
    if (ev._major != CORBA_NO_EXCEPTION) {
        CORBA_exception_free (&ev);
        return NULL;
    }
    
    CORBA_exception_free (&ev);
    
    control_widget = bonobo_widget_new_control_from_objref (
            corba_control, bonobo_ui_component_get_container (priv->uic));
    
    cf = bonobo_widget_get_control_frame (BONOBO_WIDGET (control_widget));
    pb = bonobo_control_frame_get_control_property_bag (cf, NULL);
    
    bonobo_control_frame_set_autoactivate (cf, TRUE);

    bonobo_event_source_client_add_listener (
        pb, addressbook_entry_changed,
        "Bonobo/Property:change:entry_changed",
        NULL, hdrs);

        return control_widget;
#endif
}

static void
post_browser_response (EMFolderSelector *emfs, int response, EMsgComposerHdrs *hdrs)
{
    if (response == GTK_RESPONSE_OK) {
        GList *uris = em_folder_selector_get_selected_uris (emfs);
        e_msg_composer_hdrs_set_post_to_list (hdrs, uris);
        hdrs->priv->post_custom = FALSE;
        g_list_foreach (uris, (GFunc) g_free, NULL);
        g_list_free (uris);
    }
    
    gtk_widget_destroy ((GtkWidget *) emfs);
}

static void
post_browser_clicked_cb (GtkButton *button, EMsgComposerHdrs *hdrs)
{
    EMFolderTreeModel *model;
    EMFolderTree *emft;
    GtkWidget *dialog;
    GList *post_items;
    
    model = mail_component_peek_tree_model (mail_component_peek ());
    emft = (EMFolderTree *) em_folder_tree_new_with_model (model);
    em_folder_tree_set_multiselect (emft, TRUE);
    em_folder_tree_set_excluded(emft, EMFT_EXCLUDE_NOSELECT|EMFT_EXCLUDE_VIRTUAL|EMFT_EXCLUDE_VTRASH);

    dialog = em_folder_selector_new (emft, EM_FOLDER_SELECTOR_CAN_CREATE,
                                     _("Posting destination"),
                                     _("Choose folders to post the message to."), NULL);
    
    post_items = e_msg_composer_hdrs_get_post_to (hdrs);    
    em_folder_selector_set_selected_list ((EMFolderSelector *) dialog, post_items);
    g_list_foreach (post_items, (GFunc) g_free, NULL);
    g_list_free (post_items);
    
    g_signal_connect (dialog, "response", G_CALLBACK (post_browser_response), hdrs);
    gtk_widget_show (dialog);
}

static void
post_entry_changed_cb (GtkButton *button, EMsgComposerHdrs *hdrs)
{
    hdrs->priv->post_custom = TRUE;
}

static EMsgComposerHdrPair 
header_new_recipient (EMsgComposerHdrs *hdrs, const char *name, const char *tip)
{
    EMsgComposerHdrsPrivate *priv;
    EMsgComposerHdrPair ret;
    
    priv = hdrs->priv;
    
    ret.label = gtk_button_new_with_mnemonic (name);
    GTK_OBJECT_UNSET_FLAGS (ret.label, GTK_CAN_FOCUS);
    g_signal_connect_data (ret.label, "clicked",
                   G_CALLBACK (address_button_clicked_cb),
                   e_msg_composer_hdrs_and_string_create (hdrs, name),
                   (GClosureNotify) e_msg_composer_hdrs_and_string_free,
                   0);
    
    gtk_tooltips_set_tip (hdrs->priv->tooltips, ret.label,
                  _("Click here for the address book"),
                  NULL);
    
    ret.entry = create_addressbook_entry (hdrs, name);
    
    return ret;
}

static void
entry_changed (GtkWidget *entry, EMsgComposerHdrs *hdrs)
{
    const char *subject;
    
    subject = e_msg_composer_hdrs_get_subject (hdrs);
    g_signal_emit (hdrs, signals[SUBJECT_CHANGED], 0, subject);
    g_signal_emit (hdrs, signals[HDRS_CHANGED], 0);
}

static void
create_headers (EMsgComposerHdrs *hdrs)
{
    EMsgComposerHdrsPrivate *priv = hdrs->priv;
    AtkObject *a11y;    
    /*
     * Reply-To:
     *
     * Create this before we call create_from_optionmenu,
     * because that causes from_changed to be called, which
     * expects the reply_to fields to be initialized.
     */
    priv->reply_to.label = gtk_label_new_with_mnemonic (_("_Reply-To:"));
    priv->reply_to.entry = gtk_entry_new ();
    gtk_label_set_mnemonic_widget (priv->reply_to.label, priv->reply_to.entry);
    
    /*
     * From
     */
    priv->from.label = gtk_label_new_with_mnemonic (_("Fr_om:"));
    priv->from.entry = create_from_optionmenu (hdrs);
    gtk_label_set_mnemonic_widget (priv->from.label, e_msg_composer_hdrs_get_from_omenu (hdrs));
    
    /*
     * Subject
     */
    priv->subject.label = gtk_label_new_with_mnemonic (_("S_ubject:"));
    priv->subject.entry = gtk_entry_new ();
    gtk_label_set_mnemonic_widget (priv->subject.label, priv->subject.entry);
    g_signal_connect (priv->subject.entry, "changed",
              G_CALLBACK (entry_changed), hdrs);

    /*
     * To, CC, and Bcc
     */
    priv->to = header_new_recipient (
        hdrs, _("_To:"),
        _("Enter the recipients of the message"));
    
    priv->cc = header_new_recipient (
        hdrs, _("_Cc:"),
        _("Enter the addresses that will receive a carbon copy of the message"));
    
    priv->bcc = header_new_recipient (
        hdrs, _("_Bcc:"),
         _("Enter the addresses that will receive a carbon copy of "
           "the message without appearing in the recipient list of "
           "the message."));

    /*
     * Post-To
     */
    priv->post_to.label = gtk_button_new_with_mnemonic (_("_Post To:"));
    GTK_OBJECT_UNSET_FLAGS (priv->post_to.label, GTK_CAN_FOCUS);
    g_signal_connect (priv->post_to.label, "clicked",
              G_CALLBACK (post_browser_clicked_cb), hdrs);
    gtk_tooltips_set_tip (hdrs->priv->tooltips, priv->post_to.label,
                  _("Click here to select folders to post to"),
                  NULL);
    
    priv->post_to.entry = gtk_entry_new ();
    a11y = gtk_widget_get_accessible (priv->post_to.entry);
    if (a11y != NULL) {
        atk_object_set_name (a11y, _("Post To:"));  
    }
    g_signal_connect(priv->post_to.entry, "changed",
             G_CALLBACK (post_entry_changed_cb), hdrs);
}

static void
attach_couple (EMsgComposerHdrs *hdrs, EMsgComposerHdrPair *pair, int line)
{
    gtk_table_attach (GTK_TABLE (hdrs),
              pair->label, 0, 1,
              line, line + 1,
              GTK_FILL, GTK_FILL, 3, 3);
    
    gtk_table_attach (GTK_TABLE (hdrs),
              pair->entry, 1, 2,
              line, line + 1,
              GTK_FILL | GTK_EXPAND, 0, 3, 3);
}

static void
attach_headers (EMsgComposerHdrs *hdrs)
{
    EMsgComposerHdrsPrivate *p = hdrs->priv;
    
    attach_couple (hdrs, &p->from, LINE_FROM);
    attach_couple (hdrs, &p->reply_to, LINE_REPLYTO);
    attach_couple (hdrs, &p->to, LINE_TO);
    attach_couple (hdrs, &p->cc, LINE_CC);
    attach_couple (hdrs, &p->bcc, LINE_BCC);
    attach_couple (hdrs, &p->post_to, LINE_POSTTO);
    attach_couple (hdrs, &p->subject, LINE_SUBJECT);
}

static void
set_pair_visibility (EMsgComposerHdrs *h, EMsgComposerHdrPair *pair, int visible)
{
    if (visible /*& h->visible_mask*/) {
        gtk_widget_show (pair->label);
        gtk_widget_show (pair->entry);
    } else {
        gtk_widget_hide (pair->label);
        gtk_widget_hide (pair->entry);
    }
}

static void
headers_set_visibility (EMsgComposerHdrs *h, int visible_flags)
{
    EMsgComposerHdrsPrivate *p = h->priv;
    
    /* To is always visible if we're not doing Post-To */
    if (!(h->visible_mask & E_MSG_COMPOSER_VISIBLE_POSTTO))
        visible_flags |= E_MSG_COMPOSER_VISIBLE_TO;
    else
        visible_flags |= E_MSG_COMPOSER_VISIBLE_POSTTO;
    
    set_pair_visibility (h, &p->from, visible_flags & E_MSG_COMPOSER_VISIBLE_FROM);
    set_pair_visibility (h, &p->reply_to, visible_flags & E_MSG_COMPOSER_VISIBLE_REPLYTO);
    set_pair_visibility (h, &p->to, visible_flags & E_MSG_COMPOSER_VISIBLE_TO);
    set_pair_visibility (h, &p->cc, visible_flags & E_MSG_COMPOSER_VISIBLE_CC);
    set_pair_visibility (h, &p->bcc, visible_flags & E_MSG_COMPOSER_VISIBLE_BCC);
    set_pair_visibility (h, &p->post_to, visible_flags & E_MSG_COMPOSER_VISIBLE_POSTTO);
    set_pair_visibility (h, &p->subject, visible_flags & E_MSG_COMPOSER_VISIBLE_SUBJECT);
}

static void
headers_set_sensitivity (EMsgComposerHdrs *h)
{
    /* these ones are always on */
    bonobo_ui_component_set_prop (
        h->priv->uic, "/commands/ViewTo", "sensitive",
        h->visible_mask & E_MSG_COMPOSER_VISIBLE_TO ? "0" : "1", NULL);
    
    bonobo_ui_component_set_prop (
        h->priv->uic, "/commands/ViewPostTo", "sensitive",
        h->visible_mask & E_MSG_COMPOSER_VISIBLE_POSTTO ? "0" : "1", NULL);
}

void
e_msg_composer_hdrs_set_visible_mask (EMsgComposerHdrs *hdrs, int visible_mask)
{
    g_return_if_fail (E_IS_MSG_COMPOSER_HDRS (hdrs));
    
    hdrs->visible_mask = visible_mask;
    headers_set_sensitivity (hdrs);
}

void
e_msg_composer_hdrs_set_visible (EMsgComposerHdrs *hdrs, int visible_flags)
{
    g_return_if_fail (E_IS_MSG_COMPOSER_HDRS (hdrs));
    
    headers_set_visibility (hdrs, visible_flags);
    gtk_widget_queue_resize (GTK_WIDGET (hdrs));
}

static void
setup_headers (EMsgComposerHdrs *hdrs, int visible_flags)
{
    create_headers (hdrs);
    attach_headers (hdrs);
    
    headers_set_sensitivity (hdrs);
    headers_set_visibility (hdrs, visible_flags);
}


/* GtkObject methods.  */

static void
destroy (GtkObject *object)
{
    EMsgComposerHdrs *hdrs;
    EMsgComposerHdrsPrivate *priv;
    GSList *l, *n;
    
    hdrs = E_MSG_COMPOSER_HDRS (object);
    priv = hdrs->priv;
    
    if (priv) {
        if (priv->name_selector != NULL) {
            g_object_unref (priv->name_selector);
            priv->name_selector = NULL;
        }

        if (priv->tooltips) {
            gtk_object_destroy (GTK_OBJECT (priv->tooltips));
            g_object_unref (priv->tooltips);
            priv->tooltips = NULL;
        }
        
        if (priv->accounts) {
            g_signal_handlers_disconnect_matched(priv->accounts, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, hdrs);
            g_object_unref (priv->accounts);
            priv->accounts = NULL;
        }
        
        l = priv->from_options;
        while (l) {
            EAccount *account;
            GtkWidget *item = l->data;
            
            account = g_object_get_data ((GObject *) item, "account");
            g_object_unref (account);
            
            n = l->next;
            g_slist_free_1 (l);
            l = n;
        }
        
        priv->from_options = NULL;
        
        g_free (priv);
        hdrs->priv = NULL;
    }
    
    if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}


static void
class_init (EMsgComposerHdrsClass *class)
{
    GtkObjectClass *object_class;
    
    object_class = GTK_OBJECT_CLASS (class);
    object_class->destroy = destroy;
    
    parent_class = g_type_class_ref (gtk_table_get_type ());
    
    signals[SHOW_ADDRESS_DIALOG] =
        g_signal_new ("show_address_dialog",
                  E_TYPE_MSG_COMPOSER_HDRS,
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET(EMsgComposerHdrsClass, show_address_dialog),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    
    signals[SUBJECT_CHANGED] =