1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 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 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972
|
/*
*
* Copyright (c) International Business Machines Corp., 2001
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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
*
* Module: task.c
*/
#include <frontend.h>
#include <string.h>
#include <gtk/gtk.h>
#include "support.h"
#include "widget.h"
#include "task.h"
#include "thing.h"
#include "readable.h"
#include "pixmap.h"
#include "task_window.h"
#include "selection_cb.h"
#include "views.h"
#include "logging.h"
/*
*
* void on_task_window_destroy (GtkWidget *, gpointer)
*
* Description:
* This routine frees engine resources associated with a task
* context by calling evms_destroy_task(). This routine is
* invoked when the window that created the task is destroyed.
*
* Entry:
* widget - the window that created the task context
* user_data - contains the task handle
*
* Exit:
* The task context is destroyed.
*
*/
void on_task_window_destroy (GtkWidget *widget, gpointer user_data)
{
evms_destroy_task (GPOINTER_TO_UINT (user_data));
}
/*
*
* void on_window_destroy_free_selection_array (GtkWidget *, gpointer)
*
* Description:
* This routine frees the a handle array of current selections
*
* Entry:
* widget - the window that created the task context
* selections - pointer to handle array of current selections
*
* Exit:
* The handle array of current selections is freed.
*
*/
void on_window_destroy_free_selection_array (GtkWidget *widget, gpointer selections)
{
log_debug ("%s: Freeing handle array of current selections: %p.\n", __FUNCTION__, selections);
g_free (selections);
}
/*
*
* void on_options_notebook_destroy (GtkWidget *, GSList *)
*
* Description:
* This routine frees the linked list structures used to
* track option widget information. The option widget info
* is not removed only the links since by this time the
* widget destroy handler has freed the widget info structure
* already.
*
* Entry:
* widget - the notebook that contained the option widgets
* selections - head of the option widget info linked list
*
* Exit:
* The option widget info linked list is freed.
*
*/
void on_options_notebook_destroy (GtkWidget *widget, GSList *options)
{
log_debug ("%s: Freeing the linked list containing option widget info: %p.\n", __FUNCTION__, options);
g_slist_free (options);
}
/*
*
* void create_option_widget_list (task_handle_t, gint, GSList **, GSList **, gboolean)
*
* Description:
* This routine generates the widget list for option descriptors for the
* the given task. It also returns the option widget info structures
* created to track information on the option widget/descriptor.
*
* Entry:
* handle - the task handle
* count - the count of option descriptors available
* options - the address of the list to place the option widget info structures
* widgets - the address of the list to insert the generated widgets
* show_inactive - TRUE if widgets for inactive options are wanted
*
* Exit:
* The option widgets and option descriptor lists are returned.
*
*/
void create_option_widget_list (task_handle_t handle, gint count, GSList **options, GSList **widgets,
gboolean show_inactive)
{
gint i;
gint rc;
option_descriptor_t *option;
option_widget_info_t *info;
*widgets = NULL;
*options = NULL;
for (i=0; i < count; i++)
{
rc = evms_get_option_descriptor (handle, i, &option);
if (rc == SUCCESS)
{
if (show_inactive == TRUE || EVMS_OPTION_IS_ACTIVE (option->flags))
{
info = create_widget_from_option_descriptor (option);
if (info != NULL && info->widget != NULL)
*widgets = g_slist_append (*widgets, info->widget);
*options = g_slist_append (*options, info);
}
else
{
/*
* We're not going to show this option so free it.
*/
evms_free (option);
}
}
else
log_error ("%s: evms_get_option_descriptor() returned error code %d.\n", __FUNCTION__, rc);
}
}
/*
*
* gboolean have_required_options_been_set (GSList *)
*
* Description:
* This routine walks a linked list of option widget info
* structures and checks to see if all active and required
* options have had their value set/initialized.
*
* Entry:
* options - linked list containing option widget info
*
* Exit:
* Returns TRUE if all active/required options have
* their values set. If any one of the required options
* has not had their value set then we return FALSE.
*
*/
gboolean have_required_options_been_set (GSList *options)
{
gboolean results=TRUE;
option_widget_info_t *info;
while (options != NULL && results == TRUE)
{
if (options->data != NULL)
{
info = options->data;
if (EVMS_OPTION_IS_ACTIVE (info->option->flags) &&
EVMS_OPTION_IS_REQUIRED (info->option->flags) &&
info->has_value == FALSE)
results = FALSE;
}
options = options->next;
}
return results;
}
/*
*
* void destroy_option_widgets (GSList *)
*
* Description:
* This routine walks a linked list of option widget info
* structures and destroys them with special attention to
* GtkSpinButton widgets in order to remove any timeout
* functions it may have registered. We also disconnect
* the "focus-out-event" signal handler for text entry
* fields to avoid it executing any update signal handlers
* as we destroy the widget.
*
* Entry:
* options - linked list containing option widget info
*
* Exit:
* Returns nothing.
*
*/
void destroy_option_widgets (GSList *options)
{
option_widget_info_t *info;
while (options != NULL)
{
if (options->data != NULL)
{
info = options->data;
if (GTK_IS_SPIN_BUTTON (info->widget))
{
GtkSpinButton *spin = GTK_SPIN_BUTTON (info->widget);
if (spin->timer)
{
gtk_timeout_remove (spin->timer);
spin->timer = 0;
spin->timer_calls = 0;
spin->need_timer = FALSE;
}
}
else if (GTK_IS_ENTRY (info->widget) && EVMS_OPTION_IS_ACTIVE (info->option->flags))
gtk_signal_disconnect_by_func (GTK_OBJECT (info->widget),
GTK_SIGNAL_FUNC (on_option_entry_focus_out),
info);
gtk_widget_destroy (info->widget);
}
options = options->next;
}
}
/*
*
* gchar* get_task_action_string (task_handle_t)
*
* Description:
* This routine returns a string corresponding to the task
* operation at hand, i.e. "Create", "Expand", etc.
*
* Entry:
* task - the task context handle
*
* Exit:
* Returns a dynamically allocated string containing the task
* operation action.
*
*/
gchar* get_task_action_string (task_handle_t task)
{
gint rc;
gchar *action_text=NULL;
task_action_t action;
rc = evms_get_task_action (task, &action);
if (rc == SUCCESS)
{
switch (action)
{
case EVMS_Task_Create:
case EVMS_Task_Create_Container:
action_text = g_strdup (_("Create"));
break;
case EVMS_Task_Assign_Plugin:
action_text = g_strdup (_("Assign"));
break;
case EVMS_Task_Expand:
case EVMS_Task_Expand_Container:
action_text = g_strdup (_("Expand"));
break;
case EVMS_Task_Shrink:
action_text = g_strdup (_("Shrink"));
break;
case EVMS_Task_Slide:
action_text = g_strdup (_("Slide"));
break;
case EVMS_Task_Move:
action_text = g_strdup (_("Move"));
break;
case EVMS_Task_fsck:
action_text = g_strdup (_("Check"));
break;
case EVMS_Task_mkfs:
action_text = g_strdup (_("Make"));
break;
case EVMS_Task_defrag:
action_text = g_strdup (_("Defragment"));
break;
default:
log_debug ("%s: Uknown task action %d received.\n", __FUNCTION__, action);
break;
}
}
return action_text;
}
/*
*
* handle_array_t* make_handle_array_from_selection_list (GSList *selections)
*
* Description:
* This routine takes a selection list from GtkCList widget and extracts
* the data (object handles associated with the list row) and generates
* a handle_array_t filled with valid (non-zero) handles.
*
* Entry:
* selections - linked list with handles corresponding to rows selected
*
* Exit:
* The address of the handle array containing the object
* handles is returned or NULL if the array was not created.
*
*/
handle_array_t* make_handle_array_from_selection_list (GSList *selections)
{
gint count;
handle_array_t *harray=NULL;
count = g_slist_length (selections);
if (count > 0)
{
gint i;
object_handle_t handle;
harray = g_malloc0 (sizeof (handle_array_t) + (sizeof (object_handle_t) * count));
for (i=0; i < count; i++)
{
handle = GPOINTER_TO_UINT (g_slist_nth_data (selections, i));
if (handle != 0)
{
harray->handle[harray->count] = handle;
harray->count++;
}
}
/*
* If nothing was transferred from the selection list (should never
* be the case) then free the handle array.
*/
if (harray->count == 0)
{
g_free (harray);
harray = NULL;
log_debug ("%s: Zero handles were transferred from selection list to handle array.\n", __FUNCTION__);
}
}
else
{
log_error ("%s: I can't make a handle array from an empty list!\n", __FUNCTION__);
}
return harray;
}
/*
*
* gboolean are_handle_arrays_equal (handle_array_t *, handle_array_t *)
*
* Description:
* This routine takes two handle arrays and checks to see if the counts
* match. If they do, we memcmp both to see if they contain the exact
* same handles. We should probably change this code to see if the same
* handles exist but in a different order but so what? This is really
* an optimized check anyways.
*
* Entry:
* array1 - the first handle array
* array2 - the second handle array
*
* Exit:
* Returns TRUE if the handle arrays are of the same length and contents.
*
*/
gboolean are_handle_arrays_equal (handle_array_t *array1, handle_array_t *array2)
{
gboolean arrays_equal=FALSE;
if (array1 != NULL && array2 != NULL && array1->count == array2->count)
{
gint array_size;
array_size = sizeof (handle_array_t) + ((array1->count - 1) * sizeof (object_handle_t));
arrays_equal = memcmp (array1, array2, array_size) == 0;
}
return arrays_equal;
}
/*
*
* void make_next_button_sensitive_if_necessary (GtkWidget *, GSList *)
*
* Description:
* This routine runs through the descriptors. If all the active
* and required options have set values then make the "Next"
* button sensitive otherwise it will go sensitive when at a
* minimum all required options have been set.
*
* Entry:
* widget - a widget to allow us to lookup the next button widget
* options - the list of current option descriptors
*
* Exit:
* The "Next" button is made sensitive if all required/active
* option values have been set. Otherwise, it is made insensitive.
*
*/
void make_next_button_sensitive_if_necessary (GtkWidget *widget, GSList *options)
{
GtkWidget *next_button;
next_button = lookup_widget (widget, "selection_window_next_button");
if (have_required_options_been_set (options) == TRUE)
{
gtk_widget_set_sensitive (next_button, TRUE);
gtk_widget_grab_default (next_button);
}
else
gtk_widget_set_sensitive (next_button, FALSE);
}
/*
*
* gint build_options_notebook (GtkWidget *, task_handle_t, gint, gboolean)
*
* Description:
* This routine builds the options widget notebook
* which is placed in the options frame container
* widget of the options/task window.
*
* Entry:
* window - the task/options window id
* handle - the task handle
* currpage - page to be made the current page
* show_inactive - TRUE if we should show inactive options
*
* Exit:
* Return SUCCESS if the option count was retrieved and
* sets up the option notebook. Option list and option
* notebook id are also bound to the toplevel window.
*
*/
gint build_options_notebook (GtkWidget *window, task_handle_t handle, gint currpage, gboolean show_inactive)
{
gint rc;
gint option_count;
rc = evms_get_option_count (handle, &option_count);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_option_count() returned error code %d.\n", __FUNCTION__, rc);
display_results_window (rc, NULL, _("Problem retrieving plugin option count."),
NULL, FALSE, window);
}
else
{
GtkWidget *options_frame;
log_debug ("%s: option count == %d\n", __FUNCTION__, option_count);
options_frame = gtk_object_get_data (GTK_OBJECT (window), "options_frame");
if (option_count > 0)
{
GSList *widgets=NULL;
GSList *options=NULL;
GtkWidget *notebook;
create_option_widget_list (handle, option_count, &options, &widgets, show_inactive);
notebook = create_widget_notebook (widgets, NULL, 6, currpage);
gtk_container_add (GTK_CONTAINER (options_frame), notebook);
gtk_container_set_border_width (GTK_CONTAINER (notebook), 10);
gtk_object_set_data (GTK_OBJECT (window), "options_notebook", notebook);
gtk_widget_show (notebook);
g_slist_free (widgets);
bind_option_list_to_toplevel_widget (window, options);
make_next_button_sensitive_if_necessary (window, options);
gtk_signal_connect (GTK_OBJECT (notebook), "destroy",
GTK_SIGNAL_FUNC (on_options_notebook_destroy), options);
}
else
{
GtkWidget *label;
label = gtk_label_new (_("The plugin did not provide any configuration options."));
gtk_container_add (GTK_CONTAINER (options_frame), label);
gtk_widget_show (label);
}
}
return rc;
}
/*
*
* gboolean rebuild_options_notebook (GtkWidget *)
*
* Description:
* This routine handles destroying the options notebook and building
* a new one. It is typically used invoked as an idle function so
* that we don't destroy the widgets or notebook while in the middle
* of a options widget signal handler invocation which causes bad
* side-effects.
*
* Entry:
* notebook - the id of the options notebook
*
* Exit:
* Always return FALSE to remove this function from being called
* again as an idle function.
*
*/
gboolean rebuild_options_notebook (GtkWidget *toplevel)
{
GtkWidget *notebook;
gdk_threads_enter ();
notebook = lookup_widget (toplevel, "options_notebook");
if (notebook)
{
gint currpage;
GSList *options;
GtkWidget *checkbox;
task_handle_t task;
log_debug ("%s: Rebuilding the options notebook now. notebook == %p.\n", __FUNCTION__, notebook);
checkbox = gtk_object_get_data (GTK_OBJECT (toplevel), "inactive_options_checkbutton");
task = retrieve_task_handle_from_toplevel_widget (toplevel);
options = retrieve_option_list_from_toplevel_widget (toplevel);
currpage = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
/*
* Destroy the options notebook and free the original option
* descriptor list. Note that the old option descriptors
* will be freed through evms_free() when each widget with
* an associated option descriptor is given the "destroy"
* signal.
*
* HACK! HACK! Walk the widget list ourselves to do the
* gtk_widget_destroy. If the widget is a spinbutton,
* check to see if it has a timeout function and if
* so remove it so we avoid problems later on.
*
* See bugzilla.gnome.org bug report #62539 reported by
* me (lnx1138@us.ibm.com) that details the problem.
*/
destroy_option_widgets (options);
gtk_widget_destroy (notebook);
build_options_notebook (toplevel, task, currpage,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)));
/*
* Clear the handler id as we are done.
*/
gtk_object_set_data (GTK_OBJECT (toplevel), "rebuild_options_handler_id",
GUINT_TO_POINTER (0));
}
gdk_threads_leave ();
return FALSE;
}
/*
*
* void on_display_inactive_options_check_button_toggled (GtkToggleButton *, GtkWidget *window)
*
* Description:
* This routine gets called when an the display inactive options
* checkbutton is toggled. We schedule a rebuild of the options
* notebook. The rebuild routine checks the current state of the
* this checkbox to decide whether to display inactive options in
* the options notebook.
*
* Entry:
* button - the id of the toggle button that was pressed
* window - the id of the toplevel window
*
* Exit:
* The rebuild_options_notebook is scheduled for execution on the
* next idle loop time.
*
*/
void on_display_inactive_options_check_button_toggled (GtkToggleButton *button, GtkWidget *window)
{
gtk_idle_add ((GtkFunction) rebuild_options_notebook, window);
}
/*
*
* void options_window_callout (option_widget_info_t *, value_t, task_effect_t)
*
* Description:
* This routine is the callout function called by the option widgets
* to allow us to handle management of the task/options window. This
* includes rebuilding the options notebook if EVMS_Effect_Reload_Options
* is received. We also, run through all the required options to see
* if they have been set in order to make the "Next" button sensitive.
*
* Entry:
* info - contains options descriptor, current value, and state
* value - new value
* set_side_effect - flags of sideaffects from evms_set_option_value()
*
* Exit:
* Nothing returned but either options notebook is rebuilt or "Next"
* button sensitivity is changed.
*
*/
void options_window_callout (option_widget_info_t *info, value_t value,
task_effect_t set_side_effect)
{
if (set_side_effect & EVMS_Effect_Reload_Options)
{
guint handler_id;
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (info->widget);
handler_id = GPOINTER_TO_UINT (gtk_object_get_data (GTK_OBJECT (toplevel), "rebuild_options_handler_id"));
if (handler_id == 0)
{
handler_id = gtk_idle_add ((GtkFunction) rebuild_options_notebook, toplevel);
gtk_object_set_data (GTK_OBJECT (toplevel), "rebuild_options_handler_id",
GUINT_TO_POINTER (handler_id));
log_debug ("%s: Registered idle function to rebuild options notebook %p. handler id = %u.\n",
__FUNCTION__, toplevel, handler_id);
}
else
{
log_debug ("%s: Rebuild of options notebook already pending.\n", __FUNCTION__);
}
}
else
{
GSList *options;
options = retrieve_option_list_from_toplevel_widget (info->widget);
make_next_button_sensitive_if_necessary (info->widget, options);
}
}
/*
*
* void populate_clist_with_resulting_objects (GtkCList *, handle_array_t *)
*
* Description:
* This routine populates the given resulting objects clist with
* selected information about the object.
*
* Entry:
* objects - handle array contining objects produced
*
* Exit:
* The clist is populated with information on the resulting objects.
*
*/
void populate_clist_with_resulting_objects (GtkCList *clist, handle_array_t *objects)
{
gint i;
gint rc;
gint row;
gchar *text[MAX_RO_COLUMNS];
handle_object_info_t *object;
for (i=0; i < objects->count; i++)
{
rc = evms_get_info (objects->handle[i], &object);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_info() returned error %d.\n", __FUNCTION__, rc);
}
else
{
text[RO_ICON_COLUMN] = "";
switch (object->type)
{
case EVMS_OBJECT:
case REGION:
case SEGMENT:
case DISK:
text[RO_SIZE_COLUMN] = make_sectors_readable_string (object->info.object.size);
text[RO_NAME_COLUMN] = object->info.object.name;
text[RO_TYPE_COLUMN] = make_data_type_readable_string (object->info.object.data_type);
break;
case CONTAINER:
text[RO_SIZE_COLUMN] = make_sectors_readable_string (object->info.container.size);
text[RO_NAME_COLUMN] = object->info.container.name;
text[RO_TYPE_COLUMN] = _("Container");
break;
default:
text[RO_SIZE_COLUMN] = g_strdup (_("N/A"));
text[RO_NAME_COLUMN] = _("Unknown");
text[RO_TYPE_COLUMN] = _("Unknown");
log_debug ("%s: Unhandled type %d.\n", __FUNCTION__, object->type);
break;
}
row = gtk_clist_append (clist, text);
if (row != -1)
set_clist_row_pixmap (clist, row, object->type);
g_free (text[RO_SIZE_COLUMN]);
evms_free (object);
}
}
}
/*
*
* void populate_clist_with_declined_objects (GtkCList *, declined_handle_array_t *)
*
* Description:
* This routine populates the given declined objects clist with
* the name of the declined object and the declination reason.
*
* Entry:
* declined_list - handle array containing declined objects
* with the corresponding reason codes.
*
* Exit:
* The clist is populated with information on the declined objects.
*
*/
void populate_clist_with_declined_objects (GtkCList *clist, declined_handle_array_t *declined_list)
{
gint i;
gint rc;
gint row;
gchar *text[MAX_DO_COLUMNS];
handle_object_info_t *object;
for (i=0; i < declined_list->count; i++)
{
rc = evms_get_info (declined_list->declined[i].handle, &object);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_info() returned error %d.\n", __FUNCTION__, rc);
}
else
{
text[DO_ICON_COLUMN] = "";
text[DO_REASON_COLUMN] = g_strerror (ABS(declined_list->declined[i].reason));
switch (object->type)
{
case VOLUME:
text[DO_NAME_COLUMN] = object->info.volume.name;
break;
case EVMS_OBJECT:
case REGION:
case SEGMENT:
case DISK:
text[DO_NAME_COLUMN] = object->info.object.name;
break;
case CONTAINER:
text[DO_NAME_COLUMN] = object->info.container.name;
break;
default:
text[DO_NAME_COLUMN] = _("Unknown");
log_debug ("%s: Unhandled type %d.\n", __FUNCTION__, object->type);
break;
}
row = gtk_clist_append (clist, text);
if (row != -1)
set_clist_row_pixmap (clist, row, object->type);
evms_free (object);
}
}
}
/*
*
* void display_declination_window (declined_handle_array_t *)
*
* Description:
* This routine displays a dialog window containing
* a read-only list of selection objects declined
* by the plugin.
*
* Entry:
* declined_list - handle array containing declined objects
* with the corresponding reason codes.
*
* Exit:
* The window is displayed with the list of declined
* objects and the declination reasons.
*
*/
void display_declination_window (declined_handle_array_t *declined_list)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *text_box_frame;
GtkWidget *scrolledwindow;
GtkWidget *clist;
GtkWidget *icon_col_label;
GtkWidget *object_col_label;
GtkWidget *reason_col_label;
GtkWidget *hseparator;
GtkWidget *hbuttonbox;
GtkWidget *button;
GtkTooltips *tooltips;
tooltips = gtk_tooltips_new ();
window = gtk_window_new (GTK_WINDOW_DIALOG);
vbox = gtk_vbox_new (FALSE, 0);
text_box_frame = gtk_frame_new (NULL);
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
clist = gtk_clist_new (MAX_DO_COLUMNS);
icon_col_label = gtk_label_new ("");
object_col_label = gtk_label_new (_("Storage Object"));
reason_col_label = gtk_label_new (_("Declination Reason"));
hseparator = gtk_hseparator_new ();
hbuttonbox = gtk_hbutton_box_new ();
button = gtk_button_new_with_label (_("OK"));
gtk_widget_show (vbox);
gtk_widget_show (text_box_frame);
gtk_widget_show (scrolledwindow);
gtk_widget_show (clist);
gtk_widget_show (icon_col_label);
gtk_widget_show (object_col_label);
gtk_widget_show (reason_col_label);
gtk_widget_show (hseparator);
gtk_widget_show (hbuttonbox);
gtk_widget_show (button);
gtk_window_set_title (GTK_WINDOW (window), _("Selections Declined"));
gtk_window_set_default_size (GTK_WINDOW (window), 475, -1);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_box_pack_start (GTK_BOX (vbox), text_box_frame, TRUE, TRUE, 0);
gtk_widget_set_usize (text_box_frame, 213, 300);
gtk_container_set_border_width (GTK_CONTAINER (text_box_frame), 6);
gtk_container_add (GTK_CONTAINER (text_box_frame), scrolledwindow);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
gtk_container_add (GTK_CONTAINER (scrolledwindow), clist);
gtk_clist_set_column_width (GTK_CLIST (clist), DO_ICON_COLUMN, 24);
gtk_clist_set_column_width (GTK_CLIST (clist), DO_NAME_COLUMN, 151);
gtk_clist_set_column_width (GTK_CLIST (clist), DO_REASON_COLUMN, 80);
gtk_clist_column_titles_show (GTK_CLIST (clist));
gtk_clist_set_column_widget (GTK_CLIST (clist), DO_ICON_COLUMN, icon_col_label);
gtk_clist_set_column_widget (GTK_CLIST (clist), DO_NAME_COLUMN, object_col_label);
gtk_clist_set_column_widget (GTK_CLIST (clist), DO_REASON_COLUMN, reason_col_label);
gtk_box_pack_start (GTK_BOX (vbox), hseparator, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbuttonbox, FALSE, FALSE, 0);
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox), 18);
gtk_button_box_set_child_size (GTK_BUTTON_BOX (hbuttonbox), 108, 46);
gtk_container_add (GTK_CONTAINER (hbuttonbox), button);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
populate_clist_with_declined_objects (GTK_CLIST (clist), declined_list);
gtk_tooltips_set_tip (tooltips, button, _("Close this window"), NULL);
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
gtk_widget_destroy, GTK_OBJECT (window));
gtk_signal_connect (GTK_OBJECT (clist), "select_row",
GTK_SIGNAL_FUNC (on_readonly_clist_select_row),
NULL);
gtk_widget_show (window);
}
/*
*
* GtkWidget* create_resulting_objects_window (handle_array_t *)
*
* Description:
* This routine displays a results window with a list of
* objects produced by the operation.
*
* Entry:
* objects - handle array containing objects produced
*
* Exit:
* The window is created and the list of objects is populated.
*
*/
GtkWidget* create_resulting_objects_window (handle_array_t *objects)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *frame;
GtkWidget *scrolled_window;
GtkWidget *clist;
GtkWidget *label;
GtkWidget *hseparator;
GtkWidget *hbuttonbox;
GtkWidget *button;
GtkWidget *pixmap;
GdkBitmap *mask;
GdkPixmap *gdk_pixmap;
GtkTooltips *tooltips;
get_dialog_pixmap (INFO_PIXMAP, &gdk_pixmap, &mask);
tooltips = gtk_tooltips_new ();
window = gtk_window_new (GTK_WINDOW_DIALOG);
vbox = gtk_vbox_new (FALSE, 0);
hbox = gtk_hbox_new (FALSE, 10);
frame = gtk_frame_new (NULL);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
clist = gtk_clist_new (MAX_RO_COLUMNS);
label = gtk_label_new (_("The operation completed successfully producing the objects listed below:"));
hseparator = gtk_hseparator_new ();
hbuttonbox = gtk_hbutton_box_new ();
button = gtk_button_new_with_label (_("OK"));
pixmap = gtk_pixmap_new (gdk_pixmap, mask);
gtk_window_set_title (GTK_WINDOW (window), _("Operation Completed Successfully"));
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size (GTK_WINDOW (window), 475, -1);
gtk_widget_show (vbox);
gtk_widget_show (frame);
gtk_widget_show (scrolled_window);
gtk_widget_show (clist);
gtk_widget_show (label);
gtk_widget_show (hseparator);
gtk_widget_show (hbuttonbox);
gtk_widget_show (button);
gtk_widget_show (pixmap);
gtk_widget_show (hbox);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_box_pack_start (GTK_BOX (hbox), pixmap, FALSE, FALSE, 8);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_widget_set_usize (frame, 213, 300);
gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
gtk_container_add (GTK_CONTAINER (frame), scrolled_window);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled_window), clist);
gtk_container_set_border_width (GTK_CONTAINER (clist), 12);
gtk_clist_set_column_width (GTK_CLIST (clist), RO_ICON_COLUMN, 24);
gtk_clist_set_column_width (GTK_CLIST (clist), RO_SIZE_COLUMN, 61);
gtk_clist_set_column_width (GTK_CLIST (clist), RO_TYPE_COLUMN, 80);
gtk_clist_set_column_width (GTK_CLIST (clist), RO_NAME_COLUMN, 80);
label = gtk_label_new ("");
gtk_widget_show (label);
gtk_clist_set_column_widget (GTK_CLIST (clist), RO_ICON_COLUMN, label);
label = gtk_label_new ("Size");
gtk_widget_show (label);
gtk_clist_set_column_widget (GTK_CLIST (clist), RO_SIZE_COLUMN, label);
label = gtk_label_new ("Type");
gtk_widget_show (label);
gtk_clist_set_column_widget (GTK_CLIST (clist), RO_TYPE_COLUMN, label);
label = gtk_label_new ("Name");
gtk_widget_show (label);
gtk_clist_set_column_widget (GTK_CLIST (clist), RO_NAME_COLUMN, label);
gtk_clist_column_titles_show (GTK_CLIST (clist));
gtk_box_pack_start (GTK_BOX (vbox), hseparator, FALSE, FALSE, 20);
gtk_box_pack_start (GTK_BOX (vbox), hbuttonbox, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox), 13);
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox), 9);
gtk_button_box_set_child_size (GTK_BUTTON_BOX (hbuttonbox), 118, 47);
gtk_container_add (GTK_CONTAINER (hbuttonbox), button);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_tooltips_set_tip (tooltips, button, _("Close this window"), NULL);
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
gtk_widget_destroy, GTK_OBJECT (window));
gtk_signal_connect (GTK_OBJECT (clist), "select_row",
GTK_SIGNAL_FUNC (on_readonly_clist_select_row),
NULL);
populate_clist_with_resulting_objects (GTK_CLIST (clist), objects);
return window;
}
/*
*
* void unschedule_pending_options_notebook_rebuild (GtkWidget *)
*
* Description:
* This routine removes the idle function that is scheduled
* to rebuild the options notebook.
*
* Entry:
* widget - a child widget of the toplevel widget
*
* Exit:
* Rebuild of options notebook is unscheduled if it existed.
*
*/
void unschedule_pending_options_notebook_rebuild (GtkWidget *widget)
{
guint handler_id;
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
handler_id = GPOINTER_TO_UINT (gtk_object_get_data (GTK_OBJECT (toplevel), "rebuild_options_handler_id"));
if (handler_id)
{
gtk_idle_remove (handler_id);
gtk_object_set_data (GTK_OBJECT (toplevel), "rebuild_options_handler_id",
GUINT_TO_POINTER (0));
log_debug ("%s: Unregistered pending options notebook rebuild. handle id = %u.\n",
__FUNCTION__, handler_id);
}
}
/*
*
* void on_invoke_task_button_clicked (GtkButton *, gpointer)
*
* Description:
* This routine calls the function that initiates the
* task operation (whatever that may be). It then
* displays a results screen.
*
* Entry:
* button - the button that was clicked
* user_data - contains the task handle
*
* Exit:
* Nothing is returned but the results screen will destroy
* all the windows in the window list.
*
*/
void on_invoke_task_button_clicked (GtkButton *button, gpointer user_data)
{
gint rc;
gchar *message;
GList *window_list=NULL;
task_handle_t task;
handle_array_t *resulting_objects=NULL;
task = GPOINTER_TO_UINT (user_data);
rc = evms_invoke_task (task, &resulting_objects);
if (rc != SUCCESS)
{
log_error ("%s: evms_invoke_task() returned error code %d.\n", __FUNCTION__, rc);
message = _("The operation completed with an error.");
}
else
{
task_action_t action;
if (evms_get_task_action (task, &action) == SUCCESS)
{
/*
* Make the message clearer for certain operations
* such as file system operations, e.g. FSCK and
* MKFS that the operation is scheduled to be done
* when the user commits changes.
*/
switch (action)
{
case EVMS_Task_mkfs:
case EVMS_Task_fsck:
case EVMS_Task_defrag:
message = _("The operation has been scheduled for completion when changes are committed.");
break;
default:
message = _("The operation completed successfully.");
break;
}
}
else
message = _("The operation completed successfully.");
window_list = get_window_list (GTK_WIDGET (button));
}
/*
* If the operation was a success then the window list
* will be destroyed. As part of this, the window that
* created the task will have destroyed the task upon
* invocation of its destroy function, therefore we
* make no explicit evms_destroy_task() call here.
*
* Also note that if the operation errored then the
* task context is still active and the previous
* dialog is still visible. This is to allow the
* user the chance to retry the operation or cancel
* it at their discretion.
*/
if (rc == SUCCESS)
{
/*
* Since we already successfully invoked the task and are about
* to destroy the window list and the task, make sure we abort
* any pending options notebook rebuild idle function executions.
*/
unschedule_pending_options_notebook_rebuild (GTK_WIDGET (button));
/*
* If this task produced some objects then display some
* info on them. Otherwise, display the boring results
* window.
*/
if (resulting_objects)
{
if (resulting_objects->count > 0)
{
GtkWidget *window;
window = create_resulting_objects_window (resulting_objects);
complete_display_results_window_work (window, message, window_list, TRUE);
gtk_widget_show (window);
}
else
{
display_results_window (rc, NULL, message, window_list, TRUE, NULL);
}
evms_free (resulting_objects);
}
else
{
display_results_window (rc, NULL, message, window_list, TRUE, NULL);
}
evms_destroy_task (task);
}
else
{
display_results_window (rc, NULL, message, window_list, FALSE,
gtk_widget_get_toplevel (GTK_WIDGET (button)));
}
}
/*
*
* void on_acceptable_objects_button_clicked (GtkButton *, gpointer)
*
* Description:
* This routine does all the relevant checks to see if the task window
* containing options should be created or redisplayed. For certain tasks,
* we need to create a target selection list of target acceptable objects
* (like for move). Normally, we move on to the task window where options
* for the source selection will be available. We also check now and save
* ourselves the grief if there are no options or none of them are active
* so that the we simply call on_invoke_task_button_clicked() to get the
* operation done with.
*
* Entry:
* button - the button that was clicked
* user_data - contains the task handle
*
* Exit:
*
*/
void on_acceptable_objects_button_clicked (GtkButton *button, gpointer user_data)
{
GSList *selections;
GtkWidget *clist;
task_handle_t task;
task = GPOINTER_TO_UINT (user_data);
clist = lookup_widget (GTK_WIDGET (button), "selection_window_clist");
selections = get_clist_selection_data (GTK_CLIST (clist));
if (selections != NULL)
{
GList *window_list;
GtkWidget *curr_next_window;
GtkWidget *selection_window;
handle_array_t *curr_selections;
handle_array_t *prev_selections;
selection_window = gtk_widget_get_toplevel (GTK_WIDGET(button));
window_list = get_window_list (GTK_WIDGET (selection_window));
curr_next_window = gtk_object_get_data (GTK_OBJECT (selection_window), "next_window_id");
prev_selections = gtk_object_get_data (GTK_OBJECT (selection_window), "prev_selections");
curr_selections = make_handle_array_from_selection_list (selections);
if (are_handle_arrays_equal (curr_selections, prev_selections) == FALSE)
{
gint count;
/*
* Decide a) if we need another window or can just call invoke task
* b) the next window should be the target list or c) the next window
* should be the task/options window.
*/
if (evms_get_option_count (task, &count) == SUCCESS && count == 0)
{
on_invoke_task_button_clicked (button, user_data);
}
else
{
gchar *next_button_text;
GtkWidget *next_window;
next_button_text = get_task_action_string (task);
next_window = create_standard_task_window ("Configuration Options",
next_button_text,
NULL,
on_button_clicked_display_prev_window,
on_button_clicked_destroy_window_list,
task);
if (next_window != NULL)
{
/*
* Ensure that we remove all windows starting from
* the current next window. Once that is done, add
* the new next window to the window list.
*/
if (curr_next_window != NULL)
destroy_window_list (g_list_find (window_list, next_window));
g_free (prev_selections);
window_list = g_list_append (window_list, next_window);
set_window_list (next_window, window_list);
set_window_list (selection_window, window_list);
gtk_widget_show (next_window);
gtk_widget_hide (selection_window);
bind_options_callout_to_toplevel_widget (next_window, options_window_callout);
/*
* Keep track of the current selections. If this window should
* get destroyed, make sure we free up the selection list.
*/
gtk_object_set_data (GTK_OBJECT (selection_window), "prev_selections", curr_selections);
gtk_object_set_data (GTK_OBJECT (selection_window), "next_window_id", next_window);
gtk_signal_connect (GTK_OBJECT (next_window), "destroy",
GTK_SIGNAL_FUNC (on_window_destroy_free_selection_array),
curr_selections);
}
g_free (next_button_text);
}
}
else
{
g_free (curr_selections);
gtk_widget_show (curr_next_window);
gtk_widget_hide (selection_window);
}
g_slist_free (selections);
}
else
log_error ("%s: No acceptable objects selected!\n", __FUNCTION__);
}
/*
*
* void reload_acceptable_objects (GtkCList *, task_handle_t, gint *)
*
* Description:
* This routine populates the given GtkCList with the list
* of things that are considered acceptable by the plugin
* and then selects the rows in the list corresponding to
* the objects in the selection list provided by the plugin.
*
* Entry:
* clist - address of the acceptable objects GtkCList
* task - the task context handle
* count - count of rows selected to be updated by us
*
* Exit:
* Task acceptable objects are populated and selected
* according to the current task context information.
*
*/
void reload_acceptable_objects (GtkCList *clist, task_handle_t task, gint *count)
{
gint rc;
handle_array_t *acceptable_list;
handle_array_t *selected_list;
log_entry;
rc = evms_get_acceptable_objects (task, &acceptable_list);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_acceptable_objects() returned error code %d.\n", __FUNCTION__, rc);
}
else
{
guint i;
guint min;
guint max;
gtk_signal_handler_block_by_func (GTK_OBJECT (clist),
GTK_SIGNAL_FUNC (on_acceptable_objects_clist_select_row),
GUINT_TO_POINTER (task));
gtk_signal_handler_block_by_func (GTK_OBJECT (clist),
GTK_SIGNAL_FUNC (on_acceptable_objects_clist_unselect_row),
GUINT_TO_POINTER (task));
gtk_clist_freeze (clist);
gtk_clist_clear (clist);
rc = evms_get_selected_object_limits (task, &min, &max);
if (rc == SUCCESS)
gtk_clist_set_selection_mode (clist,
((min != 1 || max != 1) ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE));
for (i=0; i < acceptable_list->count; i++)
add_thing_to_selection_list (clist, acceptable_list->handle[i], FALSE);
rc = evms_get_selected_objects (task, &selected_list);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_selected_objects () returned error code %d.\n", __FUNCTION__, rc);
}
else
{
gint row;
GSList *selections;
/*
* Find the row corresponding to each object handle in the
* selected list and mark those rows as selected in the
* order provided by the list.
*/
for (i=0; i < selected_list->count; i++)
{
row = gtk_clist_find_row_from_data (clist,
GUINT_TO_POINTER (selected_list->handle[i]));
if (row != -1)
gtk_clist_select_row (clist, row, 0);
}
/*
* Determine if anything selected make Next button
* insensitive if now below our selection minimum.
*/
selections = get_clist_selection_data (clist);
if (selections)
{
*count = g_slist_length (selections);
if (*count < min || *count == 0)
inactivate_next_button (GTK_WIDGET (clist));
g_slist_free (selections);
}
else
{
*count = 0;
inactivate_next_button (GTK_WIDGET (clist));
}
evms_free (selected_list);
}
gtk_clist_thaw (clist);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (clist),
GTK_SIGNAL_FUNC (on_acceptable_objects_clist_select_row),
GUINT_TO_POINTER (task));
gtk_signal_handler_unblock_by_func (GTK_OBJECT (clist),
GTK_SIGNAL_FUNC (on_acceptable_objects_clist_unselect_row),
GUINT_TO_POINTER (task));
evms_free (acceptable_list);
}
log_exit;
}
/*
*
* gint update_selected_objects (GtkCList *, task_handle_t, GSList *, gint *)
*
* Description:
* This routine calls the engine to update the selected objects
* list. It handles any side-effects from the operation such
* dealing with declined lists or having to reload the acceptable
* objects.
*
* Entry:
* clist - the selections window GtkCList *
* task - handle for the task at hand
* selections - linked list of object handles corresponding to
* row selections made (in the order selected)
* count - address of count of rows selected to update if necessary
*
* Exit:
* Selected objects relayed to the plugin.
*
*/
gint update_selected_objects (GtkCList *clist, task_handle_t task, GSList *selections, gint *count)
{
gint rc;
task_effect_t effect=0;
handle_array_t *handle_array;
declined_handle_array_t *declined_list=NULL;
handle_array = make_handle_array_from_selection_list (selections);
if (handle_array)
{
rc = evms_set_selected_objects (task, handle_array, &declined_list, &effect);
if (rc == SUCCESS)
{
/*
* Check to see if we ended up with a declined list or/and
* we need to reload our acceptable list and sync with the
* plugin on the selections.
*/
if ((declined_list && declined_list->count > 0) ||
(effect & EVMS_Effect_Reload_Objects))
{
if (declined_list)
{
display_declination_window (declined_list);
log_warning ("%s: Some of the object selections were declined.\n", __FUNCTION__);
evms_free (declined_list);
}
reload_acceptable_objects (clist, task, count);
}
}
else
{
gchar *message = _("Unable to tell plugin what our selections were.");
display_results_window (rc, NULL, message, NULL, FALSE,
gtk_widget_get_toplevel (GTK_WIDGET (clist)));
log_error ("%s: evms_set_selected_objects() returned error code %d.\n", __FUNCTION__, rc);
}
}
else
rc = ENODATA;
return rc;
}
/*
*
* void on_acceptable_objects_clist_select_row (GtkCList *, gint, gint, GdkEventButton *, gpointer)
*
* Description:
* This routine is called whenever a row is selected.
* We make sure that we are within the min and max
* selectable objects. If we reach the minimum number
* of selected objects, we make the "Next" button
* sensitive/active. If we attempt to exceed the max
* selectable objects, we display a friendly popup
* and nullify the select_row signal.
*
* As long as the uselect_row does not cause us to exceed
* the maximum selections indicated by the plugin then we
* call evms_set_selected_object () to update our selections.
*
* Entry:
* clist - address of GtkCList object that received select-row signal
* row - index of row selected
* column - index of column selected on current row
* event - address of structure to obtain additional context information
* user_data - contains task handle
*
* Exit:
* Returns nothing.
*
*/
void on_acceptable_objects_clist_select_row (GtkCList *clist, gint row, gint column,
GdkEventButton *event, gpointer user_data)
{
gint rc;
guint min;
guint max;
task_handle_t task = GPOINTER_TO_UINT (user_data);
rc = evms_get_selected_object_limits (task, &min, &max);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_selected_object_limits() returned error code.\n",
__FUNCTION__, rc);
}
else
{
GSList *selections;
selections = get_clist_selection_data (clist);
if (selections)
{
gint length = g_slist_length (selections);
log_debug ("%s: selection len = %d, min = %d, max = %d\n",
__FUNCTION__, length, min, max);
if (length <= max || length == -1)
{
if (update_selected_objects (clist, task, selections, &length) == SUCCESS)
{
GtkWidget *next_button;
next_button = lookup_widget (GTK_WIDGET (clist),
"selection_window_next_button");
if (length >= min && !(GTK_WIDGET_IS_SENSITIVE (next_button)))
{
gtk_widget_set_sensitive (next_button, TRUE);
gtk_widget_grab_default (next_button);
}
}
}
else
{
/*
* Ignore the selection as we have exceeded our max
*/
gtk_signal_handler_block_by_func (GTK_OBJECT (clist),
GTK_SIGNAL_FUNC (on_acceptable_objects_clist_unselect_row),
GUINT_TO_POINTER (task));
gtk_clist_unselect_row (clist, row, column);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (clist),
GTK_SIGNAL_FUNC (on_acceptable_objects_clist_unselect_row),
GUINT_TO_POINTER (task));
}
g_slist_free (selections);
}
else
{
log_debug ("%s: No selections exist.\n", __FUNCTION__);
inactivate_next_button (GTK_WIDGET (clist));
}
}
}
/*
*
* void on_acceptable_objects_clist_unselect_row (GtkCList *, gint, gint, GdkEventButton *, gpointer)
*
* Description:
* This routine is called whenever a row is unselected.
* If the number of selections falls below the minimum
* then we make the "Next" button insensitive.
*
* As long as the unselect_row does not cause us to fall
* below the minimum indicated by the plugin then we
* call evms_set_selected_object () to update our selections.
*
* Entry:
* clist - address of GtkCList object that received unselect-row signal
* row - index of row deselected
* column - index of column deselected on current row
* event - address of structure to obtain additional context information
* user_data - contains tasks handle
*
* Exit:
* Returns nothing.
*
*/
void on_acceptable_objects_clist_unselect_row (GtkCList *clist, gint row, gint column,
GdkEventButton *event, gpointer user_data)
{
gint rc;
guint min;
guint max;
task_handle_t task = GPOINTER_TO_UINT (user_data);
rc = evms_get_selected_object_limits (task, &min, &max);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_selected_object_limits() returned error code.\n",
__FUNCTION__, rc);
}
else
{
GSList *selections;
selections = get_clist_selection_data (clist);
if (selections)
{
gint length = g_slist_length (selections);
log_debug ("%s: selection len = %d, min = %d, max = %d\n",
__FUNCTION__, length, min, max);
if (length < min || length == 0)
inactivate_next_button (GTK_WIDGET (clist));
else
update_selected_objects (clist, task, selections, &length);
}
else
{
log_debug ("%s: No selections exist.\n", __FUNCTION__);
inactivate_next_button (GTK_WIDGET (clist));
}
}
}
/*
*
* void on_acceptable_objects_clist_realize (GtkWidget *, gpointer)
*
* Description:
* This routine populates the given GtkCList with the list
* of acceptable "things" for a task.
*
* Entry:
* widget - address of the task acceptable parameters GtkCList widget
* user_data - address of user data bound with signal
*
* Exit:
* Task acceptable parameters list populated with acceptable "things".
*
*/
void on_acceptable_objects_clist_realize (GtkWidget *widget, gpointer user_data)
{
gint rc;
GtkCList *clist = GTK_CLIST (widget);
task_handle_t task = GPOINTER_TO_UINT (user_data);
handle_array_t *acceptable_list;
set_selection_window_clist_column_titles (clist, _("Size"), _("Object Acceptable To Plugin"), NULL);
rc = evms_get_acceptable_objects (task, &acceptable_list);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_acceptable_objects() returned error code %d.\n", __FUNCTION__, rc);
}
else
{
guint i;
guint min;
guint max;
gboolean is_selected = (acceptable_list->count == 1);
/*
* Before populating the list check if this should be
* single-select (default) or multi-select list and
* set the mode accordingly.
*/
rc = evms_get_selected_object_limits (task, &min, &max);
if (rc == SUCCESS)
gtk_clist_set_selection_mode (clist,
((min != 1 || max != 1) ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE));
for (i=0; i < acceptable_list->count; i++)
add_thing_to_selection_list (clist, acceptable_list->handle[i], is_selected);
/*
* For some reason, when a row is selected during append to the list
* the selection is either empty or the handles in the rows end up
* with 0 for the row_data/handle. So, make an explicit call after the
* fact to try again.
*/
on_acceptable_objects_clist_select_row (clist, 0, 0, NULL, user_data);
evms_free (acceptable_list);
}
}
/*
*
* void set_task_window_instructions_label (GtkWidget *, gchar *)
*
* Description:
* This routine sets the text in the task dialog window that instructs
* the user what to do.
*
* Entry:
* window - the task dialog window id
* next_button_text - the text to be displayed on the "Next" button
*
* Exit:
* The instructions label text is set.
*
*/
void set_task_window_instructions_label (GtkWidget *window, gchar *next_button_text)
{
gchar *instruction_label_text;
GtkLabel *button_label;
GtkLabel *instruction_label;
button_label = gtk_object_get_data (GTK_OBJECT (window),
"selection_window_next_button_label");
instruction_label = gtk_object_get_data (GTK_OBJECT (window),
"selection_window_instruction_label");
instruction_label_text = g_strdup_printf (_("Make your configuration choices then select %s to complete the operation"),
next_button_text);
gtk_label_set_text (button_label, next_button_text);
gtk_label_set_text (instruction_label, instruction_label_text);
g_free (instruction_label_text);
}
/*
*
* GtkWidget* create_standard_task_window (gchar *, gchar *
* GtkSignalFunc, GtkSignalFunc,
* GtkSignalFunc,
* options_callback_callout,
* task_handle_t, gpointer)
*
* Description:
* This routine creates the generic task dialog and connects the
* appropriate signal handlers that will initiate the operation actions.
*
* Entry:
* window_title - title for the selection window
* next_button_text - label text for next button (default is "Next")
* next_button_sighandler - function to call when next button clicked
* prev_button_sighandler - function to call when prev button clicked
* cancel_button_sighandler - function to call when cancel button clicked
* handle - handle for specific task
*
* Exit:
* Generic task dialog is displayed and signal handlers
* have been connected for the corresponding actions.
*
*/
GtkWidget* create_standard_task_window (gchar *window_title, char *next_button_text,
GtkSignalFunc next_button_sighandler,
GtkSignalFunc prev_button_sighandler,
GtkSignalFunc cancel_button_sighandler,
task_handle_t handle)
{
GtkWidget *window;
window = create_task_window ();
if (window != NULL)
{
if (build_options_notebook (window, handle, 0, FALSE) == SUCCESS)
{
GtkWidget *cancel_button;
GtkWidget *prev_button;
GtkWidget *next_button;
GtkWidget *checkbox;
bind_task_handle_to_toplevel_widget (window, handle);
prev_button = gtk_object_get_data (GTK_OBJECT (window), "selection_window_prev_button");
next_button = gtk_object_get_data (GTK_OBJECT (window), "selection_window_next_button");
cancel_button = gtk_object_get_data (GTK_OBJECT (window), "selection_window_cancel_button");
checkbox = gtk_object_get_data (GTK_OBJECT (window), "inactive_options_checkbutton");
if (window_title != NULL)
gtk_window_set_title (GTK_WINDOW (window), window_title);
if (next_button_text != NULL)
set_task_window_instructions_label (window, next_button_text);
/*
* Initialize the "Cancel" button to dismiss the window
* when no signal handler is provided. Setup the "Next"
* button with the signal handler given.
*/
if (next_button_sighandler != NULL)
gtk_signal_connect (GTK_OBJECT (next_button), "clicked",
next_button_sighandler, GUINT_TO_POINTER (handle));
else
gtk_signal_connect (GTK_OBJECT (next_button), "clicked",
on_invoke_task_button_clicked, GUINT_TO_POINTER (handle));
if (prev_button_sighandler != NULL)
gtk_signal_connect (GTK_OBJECT (prev_button), "clicked",
prev_button_sighandler, GUINT_TO_POINTER (handle));
else
gtk_widget_set_sensitive(prev_button, FALSE);
if (cancel_button_sighandler != NULL)
gtk_signal_connect (GTK_OBJECT (cancel_button), "clicked",
cancel_button_sighandler, GUINT_TO_POINTER (handle));
else
gtk_signal_connect (GTK_OBJECT (cancel_button), "clicked",
on_button_clicked_destroy_window, NULL);
gtk_signal_connect (GTK_OBJECT (checkbox), "toggled",
GTK_SIGNAL_FUNC (on_display_inactive_options_check_button_toggled),
window);
}
else
{
gtk_widget_destroy (window);
window = NULL;
}
}
return window;
}
/*
* The following routines are basically getter/setter functions
* to allow binding and retrieving a task information from a toplevel
* widget.
*/
inline void bind_task_handle_to_toplevel_widget (GtkWidget *widget, task_handle_t task)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
gtk_object_set_data (GTK_OBJECT (toplevel), "task_handle", GUINT_TO_POINTER (task));
}
inline task_handle_t retrieve_task_handle_from_toplevel_widget (GtkWidget *widget)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
return GPOINTER_TO_UINT (gtk_object_get_data (GTK_OBJECT (toplevel), "task_handle"));
}
inline void bind_option_list_to_toplevel_widget (GtkWidget *widget, GSList *options)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
gtk_object_set_data (GTK_OBJECT (toplevel), "option_widget_info_list", options);
}
inline GSList* retrieve_option_list_from_toplevel_widget (GtkWidget *widget)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
return (GSList *) gtk_object_get_data (GTK_OBJECT (toplevel), "option_widget_info_list");
}
|